...

View Full Version : BBCode in PHP...



lostprophetpunk
08-05-2008, 01:20 PM
I am creating a comment system.

I have got the basic BBCode stuff down like bold, italics, underline and coloured.

But the thing I am having trouble with is the 'url' code.

The code for the 'url' tag is below...

$Text = preg_replace ('/\[url\=(.*?)\](.*?)\[\/url\]/is', '<a href="$1">$2</a>', $Text);
When I tested it, it just seems to place my website address before the typed in address like so...

http://www.mywebsite/typedinaddress

How could I fix this problem?

derzok
08-05-2008, 01:41 PM
Are you supplying an http with the typed in address? If you fail to do that, the browser will assume it's a link to a local document - even if you DO have a www. Because of that it'll just concatenate whatever you typed in to the current address in the address bar.

malfist
08-05-2008, 02:28 PM
PHP has libraries to do bbcode for you.
http://us.php.net/manual/en/book.bbcode.php

Inigoesdr
08-06-2008, 12:58 AM
PHP has libraries to do bbcode for you.
http://us.php.net/manual/en/book.bbcode.php
That's a PECL extension. A user on a shared server more than likely wouldn't be able to use it. The installation page suggests an alternative PEAR library that could be used, but it's still probably easier to write your own if you're familiar with regular expressions; specifically Perl-compatible.

malfist
08-11-2008, 08:59 PM
How is adding a PEAR library harder than writing a parser?

Inigoesdr
08-12-2008, 01:46 AM
Like I said, if you're familiar with regular expressions it would be easier to write your own than install a third-party module or class that you don't understand how it works. You don't have to worry about the author updating it, and you can make whatever changes you want whenever you want. You can also limit(or expand) the scope of the replacements to the tags you want or need, not the ones that someone else deems necessary.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum