PHP Strings


A PHP string can be Using the strlen Function
The strlen function is used to find the length of a string.

 <html><body>
 <?php
  echo strlen( "This is a test." );
 ?>
 </body></html>
len = 

   

Using the strpos Function
The strpos function is used to search for a string or character within a string. If a match is found in the string, this function will return the position of the first match. If no match is found, it will return FALSE. Let’s see if we can find the string "a test" in our string:

 <html><body>
 <?php
  echo strpos( "This is a test.", "a test" );
 ?>
 </body></html>
pos = 




The position of the string "a test" in our string is position ?. The reason that it is ?, and not ?+1, is that the first position in the string is 0, and not 1.

Review: PHP Quotes
    What is the output of the following PHP commands?
        <?php $var = 10; echo '$var'; ?>
      0
      10
      $var
      Error
Result: