PHP 5 Strings

PHP 5 Strings

PHP 5 Strings

A string is a sequence of characters, like “Hello world!”.

PHP String Functions

In this chapter we will look at some commonly used functions to manipulate strings.

Get The Length of a String

The PHP strlen() function returns the length of a string.

The example below returns the length of the string “Hello world!”:

Example

<?php
echo strlen(“Hello world!”); // outputs 12
?>

Count The Number of Words in a String

The PHP str_word_count() function counts the number of words in a string:

Example

<?php
echo str_word_count(“Hello world!”); // outputs 2
?>
Please follow and like us:

Post Author: aamirkhan

Leave a Reply

Your email address will not be published. Required fields are marked *