Hi,
How can I write a php script, so if in a varable there is the text "[link=http://www.foo.com]Stuff[/link]" (without quotes), it just displays "[link]"??
These tags would be inside lots of other plain text.
Thanks in advance,
-Stephen
Interpreting text in PHP
Re:Interpreting text in PHP
You can do this with preg_replace.
As you can see it will replace it with an actual link. You can adjust it to do exactly what you want.
Code: Select all
$text = '[link=http://www.foo.com]Stuff[/link]';
$text = preg_replace('/\[link=(.+?)\](.+?)\[\/link\]/is','<a href="\\1">\\2</a>',$text);
Re:Interpreting text in PHP
Adittionally you might want to use an array to match each replacement to what they are replaced with and use array_keys() and array_values().
This is of course if you plan to have a lot of BBCode and dont want to have a replacement for everyone.
This is of course if you plan to have a lot of BBCode and dont want to have a replacement for everyone.