Today, We want to share with you Commonly used PHP String Functions with Example.
In this post we will show you Commonly used PHP functions, hear for string functions in php with examples we will give you demo and example for implement.In this post, we will learn about The Top 15 Most Popular PHP String Functions with an example.
Commonly used PHP String Functions with Example
There are the Following The simple About Commonly used PHP String Functions with Example Full Information With Example and source code.
1. htmlentities()
Example
<?php $liveQuery = "A SMS Status is <b>bold</b>"; echo htmlentities($liveQuery); ?>
2. Htmlspecialchars()
Example
<?php $liveQuery = htmlspecialchars("<a href='jaydeep>Jaydeep</a>”, ENT_QUOTES); echo $liveQuery; ?>
3. strip_tags
Example
<?php $mytxt = '<p>Hello String.</p>'; echo strip_tags($mytxt); ?>
<?php $mytxt = '<p>Hello String.</p>'; echo strip_tags($mytxt,'<p>'); ?>
4. addslashes
Example
<?php $liveQuery = “Is Good name O’reilly?”; echo addslashes($liveQuery); // Outputs: Is Good name O\’reilly? ?>
5. stripslashes
Example
<?php $liveQuery = “Is Good name O\’reilly?”; echo stripslashes($liveQuery); // Outputs: Is Good name O’reilly? ?>
6. explode
Example
<?php $phones = “mobile1 mobile2 mobile3 mobile4 mobile5 mobile6”; $mobiles = explode(” “, $phones); // ssparate by space echo $mobiles[0]; // mobile1 echo $mobiles[1]; // mobile2 ?>
7- implode
PHP implode Example
<?php $array = array(‘jaydeep’, ’Gondaliya’, ‘phone’); $comma_separated = implode(“,”, $array); echo $comma_separated; //Output: jaydeep,Gondaliya,phone ?>
8- rand()
Example
<?php echo rand(); echo rand(100,200); echo rand(2,8); echo rand(5000,10000); ?>
9- str_replace
Example for str_replace
<?php $phone = ‘999-333-2222-77777’; echo str_replace(‘-‘, ”, $phone); //Output: 999333222277777 ?>
10- date()
Example:
<?php echo date(“d-m-Y h:i:s”); //here display prints the current date and time ?>
11. strlen()
E-junkie: Sell digital downloads online
E-junkie Provides a Copy-paste buy-now, and cart buttons for selling downloads, codes and tangible products on any website, blog, social media, email and messenger!
Also see:
Example
<?php $mystrflag = ‘patel1 PHP?’; echo strlen($mystrflag); // prints 10 $countStr = ‘ pakai code’; echo strlen($countStr); // prints 11 ?>
12. count()
Example
<?php $myarray = array(“i”,“Love”,“You”); echo count($myarray); // prints 3 ?>
13. array_combine
Example
<?php $a = array(‘good’, ‘very good’, ‘yellow’); $b = array(‘car’, ‘mobile’, ‘kites’); $c = array_combine($a, $b); print_r($c); ?>
The above example will output: Array ( [good] => car [very good] => mobile [yellow] => kites )
14. array_multisort
This is an array_multisort Example
<?php $firstArr = array(10, 100, 100, 0); $secondArr = array(1, 3, 2, 4); array_multisort($firstArr, $secondArr); var_dump($firstArr); var_dump($secondArr); ?>
The above example will output: array(4) { [0]=> int(0) [1]=> int(10) [2]=> int(100) [3]=> int(100) } array(4) { [0]=> int(4) [1]=> int(1) [2]=> int(2) [3]=> int(3) }
15. array_unique
Example:
<?php $datainput = array(“a” => “good”, “very good”, “b” => “good”, “best”, “very good”); $myresult = array_unique($datainput); print_r($myresult); ?>
The above example will output: Array ( [a] => good [0] => very good [1] => best )
16. print_r
Example:
<?php $employee = array (‘a’ => ‘jaydeep’, ‘b’ => ‘keunal’); print_r ($employee); ?>
The results would be something like: Array ( [a] => jaydeep [b] => keunal )
jQuery 15 Powerful Tips and Tricks for Developers and Web Designer
Read :
Summary
You can also read about AngularJS, ASP.NET, VueJs, PHP.
I hope you get an idea about 16 Basic String Functions in PHP.
I would like to have feedback on my Infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.