Reputation: 26581
Say if I had this tag in a string:
[phpbay]{keyword}, 30, "", "", "", "", "", "", "", "", "", "", "", "", "2", "", "", ""[/phpbay]
Could I remove it and the content between the tags? Maybe using regex? Thanks!
Upvotes: 0
Views: 1632
Reputation: 11
I personally would use str_replace or str_ireplace (case Insensitive)
$Find = array("[phpbay]","[/phpbay]");
$Replace = array("<b>","</b>");
$Source = "[phpbay]Hello World[/phpbay]";
//Couldn't get any simpler...Replace [phpbay]Content[/phpbay] with <b>Content</b>
echo str_ireplace($Find,$Replace,$Source);
Tried and tested, it works.
Hope this helps!
Upvotes: -1
Reputation: 145482
Yes, a regex might be feasible here:
$str = preg_replace('#\[phpbay][{\w},\s\d"]+\[/phpbay]#', "", $str);
This just removes the "tag" from the string if it contains only such characters as in your example. If you only wanted to remove it if it contains e.g. your example 30
or a specific {keyword}
you would have to make the regex more specific.
See also https://stackoverflow.com/questions/89718/is-there-anything-like-regexbuddy-in-the-open-source-world for some tools that might help.
Upvotes: 1
Reputation: 219920
This regEx will give you everything between those two tags:
\[phpbay](.+)\[/phpbay]
Upvotes: 1
Reputation: 360592
$string = "[phpbay]blah blah blah [/phpbay]";
$stripped_string = preg_replace('~\[\/?phpbay\]~', '', $string);
if I'm reading your question right, and want only the "blah blah blah" part to remain.
Upvotes: 1