Hi there,

I have serious probems resolving regular expressions. I wish to
replace a substring with a given pattern with results of a function
with a backreference used as argument.



SAMPLE:


function check_this_out($somevalue)
{
$url_array = '';
$i=0;

$query = "SELECT SomeRow FROM SomeTable  WHERE
SomeRowID='$somevalue';";
$result = mysql_query($query) or die (mysql_error().$query);

$someow = mysql_fetch_array($result);

var_dump($somerow);
return ($query);
}



$output = 'aliquyam erat, sed diam voluptua. [link="21"]This
is a test[/link]';

echo ($output);
echo ('<br />');

$output =
ereg_replace('\[link=&quot;([[:graph:]]+)&quot;]',check_this_out('\1'),
$output);       

echo ('<br />');        
var_dump ($output);


$output2 = 'aliquyam erat, sed diam voluptua.
[link=&quot;21&quot;]This is another test[/link]';

echo ($output);
echo ('<br />');

$output2 =
ereg_replace('/\[link=&quot;([[:graph:]]+)&quot;]/',check_this_out('\1'),
$output);       

echo ('<br />');        
var_dump ($output2);



The problem is, that although the $query string in this example  will
echo as "SELECT SomeRow FROM SomeTable WHERE SomeRowID='21';", where
$somevalue has been replaced by '21' as a result by the regular
expressions, it will eventually render as "SELECT SomeRow FROM
SomeTable WHERE SomeRowID='\1';" when mysql is called, return the row
with SomeRowID='\1', which incidently is not the row I want... I tried
type casting to no avail.

Has anybody experienced similar problems or know how to get around
this?

My php version is somewhere between 4.3.4 and 4.3.5... a 4.3.5-dev...

Best Regards 

Peter Normann


?>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to