<?php echo lcfirst("Name"); // name ?>
Tag Archives: String functions
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 ?>
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> ?>