|
Posted by Erwin Moller on 11/07/05 10:47
laredotornado@zipmail.com wrote:
> I actually want the result string (what is printed to the browser) to
> look like
>
> param1=abcd&agency_id=<?php echo $LTON; ?>¶m2=dex
>
> This PHP code:
>
> <?php
> $str = "&mine=20&agency_id=234&test=abc";
> $search = "/agency_id=\\d+/i";
> $replace = "agency_id=<?php echo \$LTON; ?>";
> $retVal = preg_replace($search, $replace, $str);
> print $retVal;
> ?>
>
> regrettably produces the wrong result
>
> &mine=20&agency_id=&test=abc
>
> How can I heal the pain? Thanks, - Dave
Hi Dave,
The answer is actually very simple:
Your desired line:
param1=abcd&agency_id=<?php echo $LTON; ?>¶m2=dex
is not a legal url.
You should urlencode all paramvalues before using them in an URL.
So try something like:
$theURL = "?param1=".urlencode("abcd");
// not very usefull, but you should do it with values
// that possible contain difficult character.
$theURL .= "&agency_id=".urlencode("<?php echo $LTON; ?>");
$theURL .= "¶m2=".urlencode("abc");
That should work.
Check your results by starting your script with:
<pre>
<? print_r($_GET); ?>
</pre>
It will spit out all name/value-pairs.
Good luck,
Erwin Moller
Navigation:
[Reply to this message]
|