Find and Replace Character of Strings in PHP

If you have strings of character and you want to find and replace specific character from string. You can do by using strpos() function of PHP. Let me explain you with an example.

Let’s say we have variable which contains string:
$member_list = ‘[“30″,”31″,”32”]’;

You want to remove [ character from it

if (strpos($member_list,'[‘) !== false) {     
   $member_list = str_replace(‘[‘, ”, $member_list);     

The above code will remove [ character from string. Similarly, we can remove ] character from it.

I hope it will help you. Enjoy Coding!

Leave a Comment