note 77255 modified in function.preg-replace by danbrown
| From: | danbrown@php.net | Date: | Fri, 28 Nov 2008 19:52:22 +0000 |
| Subject: | note 77255 modified in function.preg-replace by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-147150@lists.php.net to get a copy of this message | ||
Also worth noting is that you can use array_keys()/array_values() with preg_replace like:
<?php
$subs = array(
'/\[b\](.+)\[\/b\]/Ui' => '<strong>$1</strong>',
'/_(.+)_/Ui' => '<em>$1</em>'
...
...
);
$raw_text = '[b]this is bold[/b] and this is _italic!_';
$bb_text = preg_replace(array_keys($subs), array_values($subs), $raw_text);
?>
--was--
Also worth noting is that you can use array_keys()/array_values() with preg_replace like:
$subs = array(
'/\[b\](.+)\[\/b\]/Ui' => '<strong>$1</strong>',
'/_(.+)_/Ui' => '<em>$1</em>'
...
...
);
$raw_text = '[b]this is bold[/b] and this is _italic!_';
$bb_text = preg_replace(array_keys($subs), array_values($subs), $raw_text);
http://php.net/manual/en/function.preg-replace.php