Bug #7006 Updated: preg_replace ( string pattern, array replacement, string subject );

From: Date: Sat, 08 Jun 2002 14:06:49 +0000
Subject: Bug #7006 Updated: preg_replace ( string pattern, array replacement, string subject );
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-9848@lists.php.net to get a copy of this message
ID: 7006 Updated by: bigredlinux@yahoo.com Reported By: joel.jacobson@mobigym.se Status: Open Bug Type: Feature/Change Request Operating System: Linux 2.4.0-test7 PHP Version: 4.0.2 New Comment: I meant to say "pass it an array of matches and an array of replacements" Previous Comments: ------------------------------------------------------------------------ [2002-06-08 10:06:14] bigredlinux@yahoo.com First of all, using preg_replace here is a sin! You should be using str_replace, and if you were using str_replace you would not have to worry, since it has this feature. But, assuming that you did need to match a regular expression, well, then just do array_fill for your search and pass it an array of matches and an array of keys and you will be good to go. So no, you don't really need this feature. ------------------------------------------------------------------------ [2000-10-04 02:52:34] joel.jacobson@mobigym.se ''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 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=7006&edit=1

« previous php.bugs (#9848) next »