NOTE: Square brackets [,] have been replaced with curly brackets {,} so that the forum does not parse my post.
I'm writing a barbones forum in PHP, and am having trouble figuring out how to parse the links from the user generated {url=http://www.domain.com}domain.com{/url} to the proper HTML of < a href="http://www.domain.com/" >domain.com< /a >.
The other stuff, {b}{i}{u} is easy, 'cause you can just run str_replace to switch out the user entered tags, to the html... but with the link, the domain is a wildcard and i need to grab it from between the "{url=" and the "}".
Does anybody know how to chnage {url=http://www.domain.com}domain.com{/url} to < a href="http://www.domain.com" >domain.com< /a > with a simple string function?
Thanks in advance for the help.
Writing a forum - Parsing links
Moderator: General Moderators
you can't do it with a 'simple string function'. You're going to need a regular expression to accommodate for variable information.
maybe something like:
maybe something like:
Code: Select all
$pattern = "/\[url=\"(.*?)\"\](.*?)\[\/url\]/";{url=http://www.domain.com}domain.com{/url}
Im not shure if this is what you want but this is how i would do it
Im not shure if this is what you want but this is how i would do it
Code: Select all
$input = str_replace ('{url=', '<a href="', $input );
$input = str_replace ('}', '">', $input );
$input = str_replace ('{/url}', '</a>', $input );That's a great example of how really not to do itcoolenta wrote:{url=http://www.domain.com}domain.com{/url}
Im not shure if this is what you want but this is how i would do itCode: Select all
$input = str_replace ('{url=', '<a href="', $input ); $input = str_replace ('}', '">', $input ); $input = str_replace ('{/url}', '</a>', $input );
- Ambush Commander
- DevNet Master
- Posts: 3698
- Joined: Mon Oct 25, 2004 9:29 pm
- Location: New Jersey, US
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact: