Hey there Markus,
As usual, you've been a superb help, and I really appreciate it! My actual problem was to take
Today is a good day
[LINK]Johnny is good[/LINK]
Tomorrow will be better
[LINK]Mary is bad[/LINK]
Who cares
and then match each of the strings inside the link tags to a record in mysql, in order to grab the actual path to that file, so I could then create the url instead of the links tags.
So now, after looking at the pages you suggested, I have
- function bbcode_html($input) {
-
$bbcode = array(
-
'/\[link=(.+?)\](.+?)\[\/link\]/i'
-
);
-
-
$html = array(
-
'<a href="$1">$2</a>'
-
);
-
return preg_replace($bbcode, $html, $input);
So, if I run a query to find my magical pathway, such as
- echo bbcode_html('Today is a good day<br>
-
[LINK=myfirstpath]Johnny is good[/LINK]<br>
-
Tomorrow will be better<br>
-
[LINK=mynextpath]Mary is bad[/LINK]<br>
-
Who cares');
it will now return the html
Today is a good day
<a href='myfirstpath'>Johnny is good</a>
Tomorrow will be better
<a href='mynextpath'>Mary is bad</a>
Who cares
Which is perfect.
And I can now easily extend to using [web] tags or similar for simple url web links. It needed to be so a user could simply place tags around a web link and have it create the url for them.
I think I better get my head around regular expressions. They seem pretty powerful. Again, thanks for the advice.
Cheers
@Markus