<?php
/*
Using a function to perform an operation to an occurrence before
returning it to the replacement string does not work in preg_replace.
Consider the following code in which I want to urlencode the
replacement string which does not work.
I tried to call another function but that did not work either.
May be I do something wrong ???
Thanks,
Klaas
*/
$string = "<a href=\"/path/path2/script.php?sess ion_id=zEFCFClD mmlFFHE15416&op tion=myoption\" >My
Option</a><br>";
echo "urlencode the parameter part: [" .
preg_replace('/(<a.+href=\")([^\"]+)/i', "$1". urlencode('\\2' ),
$string) . "]\n";
echo "uppercase the parameter part: [" .
preg_replace('/(<a.+href=\")([^\"]+)/i', "$1". strtoupper("$2" ),
$string) . "]\n";
/*
Content-type: text/html
X-Powered-By: PHP/4.3.3RC4
urlencode the parameter part: [<a href="%5C2">My Option</a><br>]
uppercase the parameter part: [<a
href="/path/path2/script.php?sess ion_id=zEFCFClD mmlFFHE15416&op tion=myoption"> My
Option</a><br>]
*/
?>
/*
Using a function to perform an operation to an occurrence before
returning it to the replacement string does not work in preg_replace.
Consider the following code in which I want to urlencode the
replacement string which does not work.
I tried to call another function but that did not work either.
May be I do something wrong ???
Thanks,
Klaas
*/
$string = "<a href=\"/path/path2/script.php?sess ion_id=zEFCFClD mmlFFHE15416&op tion=myoption\" >My
Option</a><br>";
echo "urlencode the parameter part: [" .
preg_replace('/(<a.+href=\")([^\"]+)/i', "$1". urlencode('\\2' ),
$string) . "]\n";
echo "uppercase the parameter part: [" .
preg_replace('/(<a.+href=\")([^\"]+)/i', "$1". strtoupper("$2" ),
$string) . "]\n";
/*
Content-type: text/html
X-Powered-By: PHP/4.3.3RC4
urlencode the parameter part: [<a href="%5C2">My Option</a><br>]
uppercase the parameter part: [<a
href="/path/path2/script.php?sess ion_id=zEFCFClD mmlFFHE15416&op tion=myoption"> My
Option</a><br>]
*/
?>
Comment