Hello friends, this is my 8th tutorial of PHP. Today I am sharing the concept of String manipulation in PHP. Strings are almost used everywhere, so it is important that you have a good command over strings so that you can manipulate them easily to work accordingly.
Let us start with initializing a string :
 <?php  
$firststring="The quick brown fox";
$secondstring=" jumped over the lazy dog.";

//Assigning one string to another
$thirdstring = $firststring;
$thirdstring .= $secondstring;
echo $thirdstring;
?>
Here is a list of certain methods that may come handy while manipulating strings :
 Lowercase :  <?php  echo strtolower($thirdstring); ?>
Uppercase : <?php  echo strtoupper($thirdstring); ?>
Uppercase first letter : <?php  echo ucfirst($thirdstring); ?>
Uppercase words : <?php  echo ucwords($thirdstring); ?>

Length : <?php  echo strlen($thirdstring); ?>
Trim : <?php  echo $fourthstring=$firststring . trim($secondstring); ?>
Find : <?php  echo strstr($thirdstring,"brown"); ?>
Replace by String : <?php  echo str_replace("quick","so quick",$thirdstring); ?>

0 comments:

Post a Comment

Note: only a member of this blog may post a comment.