PHP case sensitive String Replace

To replace a part of the string with another string we will use str_replace function in PHP. This function will replace all the occurrence of the string we target and will replace with the string we supply. Here is an example.

<?Php $string="This is an example on how html is used in developing user-friendly web sites. By using HTML we can control the content of a page"; echo $string; echo "<br><br>"; $string=str_replace("html","PHP",$string); echo "<b>After replace</b> <br><br>$string"; ?>

If you run the above code your will see result like this

This is an example on how html is used in developing user-friendly web sites. By using HTML we can control the content of a page


After replace

This is an example on how PHP is used in developing user-friendly web sites. By using HTML we can control the content of a page


Here you can see the text html is replace by PHP but HTML is not replaced.
So str_replace() is a case sensitive string replacing function. We can use str_ireplace() to get case insensitive string replacement

Be the first to post comment on this article :


Google+
PHP String Functions

Post Comment This is for short comments only. Use the forum for more discussions.






HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us
©2000-2015 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer