About Convert a UBB-Like Code to HTML

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
detrox
Forum Newbie
Posts: 21
Joined: Wed Jun 04, 2003 1:27 am
Location: P.R.China

About Convert a UBB-Like Code to HTML

Post by detrox »

who can tell me how to convert detrox's page to <a href = 'http://detrox'>detrox's page</a>

thanks very much.
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post 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
User avatar
detrox
Forum Newbie
Posts: 21
Joined: Wed Jun 04, 2003 1:27 am
Location: P.R.China

Post 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.
owen
Forum Newbie
Posts: 15
Joined: Fri May 30, 2003 12:40 pm

preg_replace

Post 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.
Post Reply