Forum Moderators: coopster
Please could someone help? I have some PHP code which uses preg_replace which works fine when I run it without php-cgiwrap. But it doesn't work when i run with php-cgiwrap i.e the ${1} and ${2} are not substituted correctly but are printed as ${1} and ${2}. Is there a way that i could get this to work using php-cgiwrap? I need to run this as me as i am using mysql and other stuff.
My code is as follows.
if ($report_file -> loader_ok) {
$report_file -> data = preg_replace ("/(src=[\'\"])([^\#][^\:\"]*\")/im","\${1}".$settings->base_url."\${2}",$report_file -> data);
$report_file -> data = preg_replace ("/(href=[\'\"])([^\#][^\:\"]*\")/im","\${1}".$settings->base_url."\${2}",$report_file -> data);
$this -> create_html_message ($report_file);
return OK;
}
And my .htaccess file looks like:
Action application/x-pair-sphp4 /cgi-sys/php-cgiwrap/alina/php4.cgi
AddType application/x-pair-sphp4 .php
And the html after preg_replace with cgiwrap comes out incorrectly as:
<div align="left"><a ${1}http://wwWebmasterWorldebsite.com/design/${2}><img ${1}http://wwWebmasterWorldebsite.com/design/${2} width="261" height="57" border="0" alt="Business Website Design"></a></div>
What am i doing wrong?
Any help would be much appreciated.
Alina
The link looks like
<div align="left"><a href="../index.html"><img src="../website_images/website_logo1.gif" width="261" height="57" border="0" alt="Business Website Design"></a></div>
I have since discovered that it works fine for php.4.3.4 and probably higher - but i cannot find a cgiwrap for it. I need it to work for php.4.2.2 or lower. But i cannot think how to restructure the preg_replace.
Can you help?
Many thanks
Alina
Try $1 and $2 as opposed to \${1} and \${2}. Or maybe even the double whacks \\1 and \\2.
Replacement may contain references of the form \\n or (since PHP 4.0.4) $n, with the latter form being the preferred one.Resource: preg_replace() [php.net]