- Joined
- Apr 7, 2009
- Messages
- 647
- Reaction score
- 26
Hey,
This is my current BBCode parser:
Problem is, if the url for the last regex does not have http, it goes to
127.0.0.1/$1.
How can I check if the url contains 'http', and if not, add 'http'?
I know it has something to do with parse_url.
This is my current BBCode parser:
PHP:
function parseBBCode($message)
{
$message = wordwrap($message, 160, "<br />", true);
#Lets use a regex instead of str_replace.#
$message = preg_replace('|\[b\](.+?)\[\/b\]|i', '<b>$1</b>', $message);
$message = preg_replace('|\[i\](.+?)\[\/i\]|i', '<i>$1</i>', $message);
$message = preg_replace('|\[u\](.+?)\[\/u\]|i', '<u>$1</u>', $message);
$message = preg_replace('|\[img\](.+?)\[\/img\]|i', '<img src="$1" border="0" alt="$1" title="$1">', $message);
$message = preg_replace('|\[url="(.+?)"\](.+?)\[\/url\]|i', '<a href="$1" target="_blank">$2</a>', $message);
}
Problem is, if the url for the last regex does not have http, it goes to
127.0.0.1/$1.
How can I check if the url contains 'http', and if not, add 'http'?
I know it has something to do with parse_url.
Last edited:

