Jump to content

string replace with preg_replace


robbyd

Recommended Posts

Im trying to find a way to search and replace multiple instances in a string

For example if I have string like:

 

$string = '[this] is a [example] string [end]';

 

and function like:

preg_replace ( '#\[(.+?)\]#mi','',$string);

 

The output I would like is: "is a string"

However currently it outputs blank, because it takes the first [ and the last ] and replaces it with blank instead of each instance of [ ]. Any suggestions or ideas on what to change would be helpful.

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/94598-string-replace-with-preg_replace/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.