<?php $name = "Hello Name"; $name =str_replace("Name", "First Name", $name); echo $name; // Hello First Name ?>
Category Archives: PHP
Convert the first character of each word in a string into uppercase – PHP
<?php echo ucwords("hello name"); // Hello Name ?>
Convert the first letter into lower case – PHP
<?php echo lcfirst("Name"); // name ?>
Convert the first letter into uppercase – PHP
<?php echo ucfirst("name"); //Name ?>
Convert the string into upper case – PHP
<?php echo strtoupper("name"); // Name ?>
Convert the string into lower case – PHP
<?php echo strtolower("FIRST NAME") //first name ?>
Remove spaces from the beginning and end of a string – PHP
<?php echo trim(" Test "); // Test //Will remove the spaces from the beginning and end ?>
How to read all the keys or a subset of the keys of an array – PHP
<?php $testArray = array(1 => 5, "name" => "First Name"); print_r(array_keys($testArray)); //Array ( [0] => 1 [1] => name ) ?>
Check whether a variable is empty – PHP
<?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 ?>
Add backslashes in front of special characters – PHP
<?php $str = "Test's"; echo addslashes($str); //Test's ?>