PHP String Functions with example

 PHP provides a large number of built-in functions for manipulating strings. Here are a few examples of common string functions in PHP:

strlen(): This function returns the length of a string.

$str = "Hello World"; echo strlen($str); // Outputs: 11

strtolower(): This function converts a string to all lowercase letters.

$str = "Hello World"; echo strtolower($str); // Outputs: "hello world"

strtoupper(): This function converts a string to all uppercase letters.

$str = "Hello World"; echo strtoupper($str); // Outputs: "HELLO WORLD"

substr(): This function returns a portion of a string.

$str = "Hello World"; echo substr($str, 0, 5); // Outputs: "Hello"

str_replace(): This function searches for a specified value in a string and replaces it with a new value.

$str = "Hello World"; echo str_replace("World", "PHP", $str); // Outputs: "Hello PHP"

strpos(): This function searches for a specified value in a string and returns the position of the first occurrence.

$str = "Hello World"; echo strpos($str, "World"); // Outputs: 6

These are just a few examples of the string functions available in PHP. For a complete list of string functions and more detailed information, you can refer to the PHP documentation at https://www.php.net/manual/en/ref.strings.php.

Popular posts from this blog

Yii Framework In Update Time View Image In Form

Add a new column to existing table in a migration

Ajax Toggle(on/off) on-click Update