Skip to content Skip to sidebar Skip to footer

How Do I Make A Bbcode To Parse Url Tags Into Links?

How should I go about parsing a url in php? I wanna make it so it goes [url=http://www.google.com]Google[/url] Turns into: Google

Solution 1:

$post = preg_replace('/\[url=(.+?)\](.+?)\[\/url\]/', '<a href="\1">\2</a>', $post);

That will turn: [url=http://google.com]Google[/url]

Into parsed bbcode text: Google

You'll probably want to use more specific regex than just .+ to filter out potentially bad/dangerous input.

Post a Comment for "How Do I Make A Bbcode To Parse Url Tags Into Links?"