PHP Strings Function
Here are some of the most used PHP functions to manipulate strings.
strlen() - This function return the Length of a String
Example 1:
<?php
echo strlen("Hello there, how are you!"); // outputs 25
?>
echo strlen("Hello there, how are you!"); // outputs 25
?>
explode (delimiter, string)
Explode function is used to break a string into multiple strings, very useful when working with files in the form of a database. Example using explode function:
Example 2:
<? Php
$string = 'I want to learn PHP';
$array = explode(' ', $string);
echo '<pre>' .print_r ($array, true). '</pre>'; // we use pre for a better display of the array
?>
$string = 'I want to learn PHP';
$array = explode(' ', $string);
echo '<pre>' .print_r ($array, true). '</pre>'; // we use pre for a better display of the array
?>
Output:
Array
(
[0}=> I
[1}=> want
[2}=> to
[3}=> learn
[4}=> PHP
)
(
[0}=> I
[1}=> want
[2}=> to
[3}=> learn
[4}=> PHP
)
str_word_count() This function count words in a string
The PHP str_word_count() function counts the number of all words in a string.
Example 3:
<?php
echo str_word_count("Hello world! I want to learn PHP"); // outputs 7
?>
echo str_word_count("Hello world! I want to learn PHP"); // outputs 7
?>
str_replace() - Replace Text in a String
The PHP str_replace() function is one of the most used and replaces some characters with other characters in a string.
Example 4:
Replace in text "world" with "Any":
<?php
echo str_replace("world", "Any", "Hello world! I want to learn PHP");
// outputs: Hello Any! I want to learn PHP
?>
echo str_replace("world", "Any", "Hello world! I want to learn PHP");
// outputs: Hello Any! I want to learn PHP
?>
PHP String Functions - php tutorial
Online Editor
This tool makes it easy to create, adjust, and experiment with custom colors for the web.
HTML Templates

Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.
CSS HTML Layout

Find here examples of creative and unique website layouts.
Free CSS HTML Menu

Find here examples of creative and unique website CSS HTML menu.