Posted By

tmbrenneke on 09/28/09


Tagged


Versions (?)

strings


 / Published in: PHP
 

Hello World out there Hello World Hello World Hello WorldAgain

The quick brown fox jumped over the lazy dog. Lowercase: the quick brown fox jumped over the lazy dog. Uppercase: THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG. Uppercase words: The Quick Brown Fox Jumped Over The Lazy Dog. Length: 45 Trim: The quick brown foxjumped over the lazy dog. Replace by string: The super-fast brown fox jumped over the lazy dog. Repeat: The quick brown fox jumped over the lazy dog.The quick brown fox jumped over the lazy dog. Make substring: uick brown Find position: 10 Find character: zy dog.

  1. <?php
  2. $var1 = "out there";
  3. $var2 = "Hello World $var1";
  4. echo $var2;
  5. ?>
  6. <br />
  7.  
  8. <?php
  9. echo "Hello World";
  10. echo "<br />";
  11. $my_variable = "Hello World";
  12. echo $my_variable;
  13. echo "<br />";
  14. echo $my_variable . "Again"; //concatenation
  15. ?>
  16.  
  17. <br /><br />
  18. <?php
  19. $firstString = "The quick brown fox";
  20. $secondString = " jumped over the lazy dog.";
  21. $thirdString = $firstString;
  22. $thirdString .= $secondString;
  23. echo $thirdString;
  24. ?>
  25. <br />
  26. Lowercase: <?php echo strtolower($thirdString); ?><br />
  27. Uppercase: <?php echo strtoupper($thirdString); ?><br />
  28. Uppercase words: <?php echo ucwords($thirdString); ?><br />
  29. Length: <?php echo strlen($thirdString); ?><br />
  30. Trim: <?php echo $firstString . trim($secondString); ?><br />
  31. Replace by string: <?php echo str_replace("quick", "super-fast", $thirdString);
  32. ?><br />
  33. Repeat: <?php echo str_repeat($thirdString, 2); ?> <br />
  34. Make substring: <?php echo substr($thirdString, 5, 10); ?> <br />
  35. Find position: <?php echo strpos($thirdString, "brown"); ?> <br />
  36. Find character: <?php echo strstr($thirdString, "z"); ?> <br />

Report this snippet  

You need to login to post a comment.