ID: 24375
User updated by: zvorygin at kenjitsu dot net
Reported By: zvorygin at kenjitsu dot net
Status: Bogus
Bug Type: PCRE related
Operating System: Win2000
PHP Version: 4.3.1
New Comment:
Hello,
It's me, zvorygin again.
Downloading of new version is in process. I have reread documentation
few times again and found:
-------------
Every parameter to preg_replace() (except limit) can be an array.
If subject is an array, then the search and replace is performed on
every entry of subject, and the return value is an array as well.
If pattern and replacement are arrays, then preg_replace() takes a
value from each array and uses them to do search and replace on
subject. If replacement has fewer values than pattern, then empty
string is used for the rest of replacement values. 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.
/e modifier makes preg_replace() treat the replacement parameter as PHP
code after the appropriate references substitution is done. Tip: make
sure that replacement constitutes a valid PHP code string, otherwise
PHP will complain about a parse error at the line containing
preg_replace().
-------------------------
So we don't see what will happen if pattern is string and replacement
is array!
Maybe, Developers has just forgot to take a look at this case?
because when I replace:
-------------
return preg_replace("/<!--#(.*)-->/U",$repl,$text);
-------------
with
------------
$pattern=array("/<!--&(.*)-->/U");
return preg_replace($pattern,$repl,$text);
------------
Everything works nice!
Previous Comments:
------------------------------------------------------------------------
[2003-06-28 12:18:14] [EMAIL PROTECTED]
Thank you for taking the time to report a problem with PHP.
Unfortunately you are not using a current version of PHP --
the problem might already be fixed. Please download a new
PHP version from http://www.php.net/downloads.php
If you are able to reproduce the bug with one of the latest
versions of PHP, please change the PHP version on this bug report
to the version you tested and change the status back to "Open".
Again, thank you for your continued support of PHP.
4.3.2 was released already...
------------------------------------------------------------------------
[2003-06-28 12:10:55] zvorygin at kenjitsu dot net
Description:
------------
I wrote a simple program which had to replace some strings in file
using regular expressions and display the reult.
I used next sample templatesource_text here:
---------------------
<!--%seclevel_num="0"-->
<!--%description_text="Default header"-->
<html>
<head>
<title><!--#TITLE--></title>
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1251">
</head>
<body>
----------------------
Reproduce code:
---------------
-------------------
include("classes//class_template.php");
$templ= new template();
$templ->templatedir_text="template//default//";
$templ->loadTemplate("default_header.html");
echo($templ->applyTransform());
-------------------
function applyTransform $matches_array=NULL,$replace_array=NULL){
$repl=array("qwerty1","qwerty2","qwerty3","qwerty4");
$text=$this->templatesource_text;
return preg_replace("/<!--#(.*)-->/U",$repl,$text);
-------------------
Expected result:
----------------
I was expected to see may be warning, or error, but NOT application
error.
Also when I use "preg_replace("/<!--%(.*)-->/U",$repl,$text);"
everythjing is fine
Actual result:
--------------
php.exe-application error
The instruction at "0x10074d7e" referenced memory at "0x00a4a000" the
memory could not be "read"...
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=24375&edit=1