note 50003 deleted from function.preg-replace by colder

From: Date: Mon, 18 Jun 2007 19:52:35 +0000
Subject: note 50003 deleted from function.preg-replace by colder
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-127673@lists.php.net to get a copy of this message
Note Submitter: gbaatard at iinet dot net dot au ---- 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:)

« previous php.notes (#127673) next »