Forum Moderators: coopster

Message Too Old, No Replies

php-cgiwrap with preg_replace

Trying to get preg_replace to work with php-cgiwrap.

         

Alina

9:50 am on Jun 30, 2004 (gmt 0)

10+ Year Member



Hello

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

coopster

5:39 pm on Jun 30, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, Alina!

What does the link look like prior to your code execution?

Alina

6:24 pm on Jun 30, 2004 (gmt 0)

10+ Year Member



Hi coopster :-)

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

coopster

6:46 pm on Jun 30, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Hmmm. I don't have a cgi install to test on. This is a stab in the dark, but have you tried using alternate syntax for the references?

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]

Alina

7:13 pm on Jun 30, 2004 (gmt 0)

10+ Year Member



hi coopster.

i tried \\1 and \\2 earlier and that threw up an error. $1 and $2 may work - don't know. But i have just located a cgiwrap for 4.3.4 - so the preg-replace works now! so i don't need to change anything.

many many thanks for all the help

Alina