Reputation: 768
Maybe it's just too late for me to do this, but I'm trying to replace a character between 2 string with regex in PHP.
Example string:
other | text [tag]text|more text|and more[/tag] end | text
My goal is to replace |
with <br/>
between [tag]
and [/tag]
.
Tried with this, seems it wasn't that easy though:
/<td>(\|)<td>/gsi
Searched a bit, but couldn't make out an answer with the stuff I found.
Hope you can help, thanks
Upvotes: 0
Views: 342
Reputation: 225281
First, find what's inside [tag]
s, then find the pipes. PHP 5.3:
$result = preg_replace_callback('/\[tag\](.+?)\[\/tag\]/i', function($match) {
return str_replace('|', '<br />', $match[1]);
}, $str);
Upvotes: 3