note 50003 added to function.preg-replace
| From: | gbaatard at iinet dot net dot au | Date: | Tue, 15 Feb 2005 05:56:34 +0000 |
| Subject: | note 50003 added to function.preg-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-85050@lists.php.net to get a copy of this message | ||
on the topic of implementing forum code ([b][/b] to <b></b> etc), i found this worked
well...
<?php
$body = preg_replace('/\[([biu])\]/i', '<\\1>', $body);
$body = preg_replace('/\[\/([biu])\]/i', '</\\1>', $body);
?>
First line replaces [b] [B] [i] [I] [u] [U] with the appropriate html tags(<b>, <i>,
<u>)
Second one does the same for closing tags...
For urls, I use...
<?php
$body = preg_replace('/\s(\w+:\/\/)(\S+)/', ' <a href="\\1\\2"
target="_blank">\\1\\2</a>', $body);
?>
and for urls starting with www., i use...
<?php
$body = preg_replace('/\s(www\.)(\S+)/', ' <a href="http://\\1\\2"
target="_blank">\\1\\2</a>', $body);
?>
Pop all these lines into a function that receives and returns the text you want 'forum
coded' and away you go:)
----
Manual Page -- http://www.php.net/manual/en/function.preg-replace.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+50003
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+50003&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+50003&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+50003&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+50003&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+50003&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+50003&report=yes
Search -- http://master.php.net/manage/user-notes.php