String Manipulation 

1. Changing Case


<?


$full_name = 'nicholas cage';


$full_name = ucwords($full_name);


echo $full_name;


 


// Use strtolower and strtoupper functions too


?>



2. Trimming White Space


<?


trim(" Test "); // Remove white space from both sides of a string


ltrim(" Test "); // Remove white space from left side of a string


rtrim(" Test "); // Remove white space from right side of a string


?>



3. Shuffle characters


<?


$full_name = 'nicholas cage';


$full_name = str_shuffle($full_name);


echo $full_name;


?>



4. Finding String Positions with strpos


<?


$full_name = "nicholas";
$letter_position = strpos($full_name,"h");
echo $letter_position;


?>



5. Splitting a line of text


<?


$full_name = "Jaydra,Joe,Elizabeth,Abby,Vilma,Laura";
$names = explode(",",$full_name);  // Returns an array by breaking string with "," sign
echo $names[0];


?>

                    

Copyright © 2008 VisualBuilder. All rights reserved