PHP 4.0 Bug #7006: preg_replace ( string pattern, array replacement, string subject );
| From: | joel dot jacobson at mobigym dot se | Date: | Wed, 04 Oct 2000 06:52:34 +0000 |
| Subject: | PHP 4.0 Bug #7006: preg_replace ( string pattern, array replacement, string subject ); | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-34190@lists.php.net to get a copy of this message | ||
From: joel.jacobson@mobigym.se
Operating system: Linux 2.4.0-test7
PHP version: 4.0.2
PHP Bug Type: Feature/Change Request
Bug description: preg_replace ( string pattern, array replacement, string subject );
''If pattern is an array and replacement is a string; then this replacement string is used
for every value of pattern. The converse would not make sense, though.''
(http://www.php.net/manual/function.preg-replace.php)
I don't agree. The converse is a feature that I would like to be available.
Have a look at the following example:
<?php
$tvPrograms = array ( 'Simpsons', 'Southpark', 'Disney Time' );
$data =
'<tr><td>%col%</td><td>%col%</td><td>%col%</td></tr>';
$htmlDoc = preg_replace ( '/%col%/', $tvPrograms, $data );
print $htmlDoc;
?>
This will not work. But wouldn't it be nice if it did?
That is, replace match number n with $tvPrograms[n] in $data.
Thanks in advance for any comments.
Best regards, Joel Jacobson