How to Check the Length of a PHP String

How to Check the Length of a PHP String thumbnail
Strings are used in PHP to read and display information.

PHP is an object-oriented scripting language embedded in HTML source files. It is a general-purpose language designed to make dynamic Web pages. Strings, which are sequences of characters meant to be read literally, are used in PHP to read in data as well as display information on a Web page. Determining the length of a string can be used to perform checks and test if data requirements are met. Running PHP script requires a Web server and a Web browser.

Things You'll Need

  • Text editor
Show More

Instructions

    • 1

      Open your text editor.

    • 2

      Invoke the strlen() method by typing the following code:

      strlen ( string )

      Substitute the string whose length you want to find in place of the "string" argument. The strlen() method will return an integer whose value is the length of the string.

    • 3

      Enclose the code from Step 2 in PHP tags like this:

      <?php and ?>

      The PHP tags tells the Web browser to execute PHP code.

    • 4

      Save the file, and reload the Web page.

Related Searches:

References

  • Photo Credit Comstock/Comstock/Getty Images

Comments

Related Ads

Featured