This is a discussion on preg_match() question: Operation to occurrence does not result within the PHP Language forums, part of the PHP Programming Forums category; <?php /* Using a function to perform an operation to an occurrence before returning it to the replacement string does ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
<?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?session_id=zEFCFClDmmlFFHE15416&option= 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?session_id=zEFCFClDmmlFFHE15416&option= myoption">My Option</a><br>] */ ?> |
|
|||
|
thenetflyer wrote:
.... > $string = "<a href=\"/path/path2/script.php?session_id=zEFCFClDmmlFFHE15416&option= myoption\">My > Option</a><br>"; > > echo "urlencode the parameter part: [" . > preg_replace('/(<a.+href=\")([^\"]+)/i', "$1". urlencode('\\2'), (snip) You need to specify the /e option in the regular expression -- USENET would be a better place if everybody read: : mail address : http://www.catb.org/~esr/faqs/smart-questions.html : is valid for : http://www.netmeister.org/news/learn2quote2.html : "text/plain" : http://www.expita.com/nomime.html : to 10K bytes : |