note 61411 deleted from function.preg-replace by colder
| From: | colder@php.net | Date: | Mon, 18 Jun 2007 19:57:34 +0000 |
| Subject: | note 61411 deleted from function.preg-replace by colder | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-127680@lists.php.net to get a copy of this message | ||
Note Submitter: Rebort
----
Following up on pietjeprik at gmail dot com's great string to parse [url] bbcode:
<?php
$url = '[url=http://www.foo.org]The link[/url]';
$text = preg_replace("/\[url=(\W?)(.*?)(\W?)\](.*?)\[\/url\]/", '<a
href="$2">$4</a>', $url);
?>
This allows for the user to enter variations:
[url=http://www.foo.org]The link[/url]
[url="http://www.foo.org"]The link[/url]
[url='http://www.foo.org']The link[/url]
or even
[url=#http://www.foo.org#]The link[/url]
[url=!http://www.foo.org!]The link[/url]