Re: dynamic link converter
| From: | Nik Makepeace | Date: | Thu, 06 Mar 2003 03:03:33 +0000 |
| Subject: | Re: dynamic link converter | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-138406@lists.php.net to get a copy of this message | ||
On Thu, 2003-03-06 at 05:49, electroteque wrote:
> hi there i am trying tom preg_replace on a string enclosed in brackets to
> denote a dynamic link
This works, if I understand you correctly:
<?php
$message = "[http://www.eletroteque.dyndns.org/index_html.php|Eletroteque Multimedia]";
echo $message = preg_replace(
"/\[((http(s?):\/\/)|(www\.))([\w\.]+)([\/\w+\.]+)\|([\s\w\.]+)\b\]/i",
"<a href=\"http\\3://\\4\\5\\6\"
target=\"_blank\">\\7</a>",
$message
);
?>
But wouldn't it be easier just to do use a pattern like this
"/\[([^|]+)\|([^\]]+)/"
which gets everything between [ and | (the URI) and | and ] (the link
name)?
Nik