Testing for Substrings : substr_count « String « PHP






Testing for Substrings

 
<?php
  $counter = substr_count ("Hello World!","o");
  echo "There are " . $counter . " instance (s) of \"o\" in Hello World!.";
?>
<?php

  $theclientstext = "Hello, how are you today? I am fine!";

  if (strlen ($theclientstext) >= 30){
    echo substr ($theclientstext,0,29);
  } else {
    echo $theclientstext;
  }

?>
  
  








Related examples in the same category

1.Counting the Occurrences of a Substring
2.substr_count() function returns the number of times substring occurs in string.
3.substr_count.php