Page 1 of 1

About Convert a UBB-Like Code to HTML

Posted: Sun Jun 08, 2003 10:19 am
by detrox
who can tell me how to convert detrox's page to <a href = 'http://detrox'>detrox's page</a>

thanks very much.

Posted: Sun Jun 08, 2003 8:08 pm
by McGruff
Umm.. I'm guessing you wrote this without the spaces and it got parsed:

[ url ] http://detrox'>detrox's page [ /url ]

Try a str_replace to search for [ url ] and [ /url ] and then replace former with '<a href="' and latter with $var. '">' . $var . '</a>'

str_replace is case sensitive - preg_match if that's an issue

Posted: Sun Jun 08, 2003 8:20 pm
by detrox
Sorry I did so, I'm sorry.
and I mean that if i have a lot of things of that kind how can i convert it.

preg_replace

Posted: Mon Jun 09, 2003 11:41 am
by owen
This is what I use:

Code: Select all

$str=preg_replace("/\&#1111;url\](&#1111;^\&#1111;]*?)\&#1111;\/url\]/i","<a target='_blank' href='\\1'>\\1</a>",$str);
It can be modified to parse other things as well. Read up on the preg_replace function to understand what it's doing.

Avoid using str_replace especially on tags that - if left open can break your html layout.