<?php // Example 1 $string=""; if(empty($string)) echo "Empty string"; else echo "Not an empty string"; //Empty string ?> <?php // Example 2 $strng="Test"; if(empty($strng)) echo "Empty string"; else echo "Not an empty string"; //Not an empty string ?>
Tag Archives: PHP
Add backslashes in front of special characters – PHP
<?php $str = "Test's"; echo addslashes($str); //Test's ?>
Removes backslashes – PHP
<?php $str = "Test's"; echo stripslashes($str); //Test's ?>
Converts characters to HTML entities – PHP
<?php $str = "<p>First Name</p>"; echo htmlentities($str); //<p>First Name</p> ?>
Randomizes the order of the elements in an array – PHP
$numbers = range(0, 9); shuffle($numbers); foreach ($numbers as $number) { echo $number; }
Create an array containing a range of elements – PHP
<?php $numbers = range(0, 9); foreach($numbers as $value) echo $value." "; //Will output 0 1 2 3 4 5 6 7 8 9 ?>
Read Buffers – PHP
<?php ob_get_contents(); ?>
How to set default time zone – PHP
<?php date_default_timezone_set('America/Los_Angeles'); ?>
Reverse the order of elements in an array – PHP
<?php $testData= array('Test1', 'Test2', 'Test3'); print_r(array_reverse($testData)); //Array ( [0] => Test3 [1] => Test2 [2] => Test1 ) ?>
Find the last element of an array – PHP
<?php $testData= array('Test1', 'Test2', 'Test3'); echo end($testData); // Test3 ?>