preg_match() question: Operation to occurrence does not result

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 ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 06-03-2004
thenetflyer
 
Posts: n/a
Default preg_match() question: Operation to occurrence does not result

<?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>]
*/

?>
Reply With Quote
  #2 (permalink)  
Old 06-03-2004
Pedro Graca
 
Posts: n/a
Default Re: preg_match() question: Operation to occurrence does not result

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 :
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 08:37 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0