5 Most Useful PHP String Functions You Should Know

When we start working with PHP String functions, we have to learn some useful string operation using PHP predefined functions.

Today we talk about some most used String functions which use to manipulate user defined strings. There are 5 most used PHP string manipulation functions listed below,

PHP String functions

Complete Explanation of PHP String functions

Substr in PHP (PHP substr())

Substr in PHP, also on the full form is called PHP substring. In PHP substring we cut out some part of the string from where we want. Using PHP substr(), in this function, we pass the required parameter than execute for getting the result. Below check the syntax of the PHP substr() function.
substr(string_name, start_position, string_length_to_cut)
PHP substr() Example:


// PHP program to explain substr()
function PHPSubstring($str){
$len = strlen($str);
echo substr($str, 4), "<br/>";
echo substr($str, 5, $len), "<br/>";
echo substr($str, -2, 8), "<br/>";
echo substr($str,-4, -5), "<br/>";

// Driver Code


//Output: oderTECH

PHP String Length (PHP strlen())

Using PHP strlen() function we can get the length of the string.
PHP strlen() Example:
// PHP program to find the
// length of a given string

$str = "php coder tech";

// prints the length of the string
// including the space
echo strlen($str);

//O/U: 14

PHP String Replace (php str_replace, php regex replace)

In PHP, if we want replace any particular string, any integer or any type of data we use php str_replace() function. Example shown below.

PHP str_replace() Example:

$my_str = 'If the facts do not fit the theory, change the facts.';

// Display replaced string
echo str_replace("facts", "truth", $my_str);

PHP String Cast

$string_var = "string value for php type";
$int_var = (int)$string_var;

User Editor to check the O/P: Click Here

PHP Escape String (escape_string PHP)

Either escape the quote:

$text1= "From time to \"time\"";
or use single quotes to denote your string:

$text1= 'From time to "time"';

Check the PHP official site to know more,


Also Read:

Happy Coding..!

Was this article helpful?
My name is Bikash Kr. Panda. I own and operate PHPCODER.TECH, my native place in Odisha. I am a Web Programmer by profession and working on more than 50 projects to date. My passion is working on the web-based project using PHP and relate to all CMS and frameworks which is based on PHP.
Posts created 163

Leave a Reply

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

Related Posts

Begin typing your search term above and press enter to search. Press ESC to cancel.

Back To Top
mariobet - supertotobet - escort -


We are now accepting Guest Posting and creation of Backlinks
This is default text for notification bar