Jump to content

Help with a regexp to extract url and contents from a BBCode


redbrad0

Recommended Posts

u mean this mate

<?php
$txt = preg_replace("/\[url\](.+?)\[\/url\]/", "<a href=\"\\1\" target=\"_blank\">\\1</a>", $txt);
$txt = preg_replace("/\(.+?)\[\/url\]/", "<a href=\"\\1\" target=\"_blank\">\\2</a>", $txt);
?>

I created a test page and I am not sure why... but the second echo does not return any output. Any idea?

 

<?php
$htmlversion = "[url=\"www.google.com/search.htm\"]>>>Search Now!<<<[/url]";
echo "htmlversion:" . $htmlversion . "<br>\r\n";

// Try and handle the [url] tag
$htmlversion = preg_replace("/\[url\](.+?)\[\/url\]/", "<a href=\"\\1\" target=\"_blank\">\\1</a>", $htmlversion);
$htmlversion = preg_replace("/\(.+?)\[\/url\]/", "<a href=\"\\1\" target=\"_blank\">\\2</a>", $htmlversion);

echo "htmlversion:" . $htmlversion . "<br>\r\n";
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.