You are here: Re: having trouble with string replacement « PHP Programming Language « IT news, forums, messages
Re: having trouble with string replacement

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; ?>&param2=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; ?>&param2=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 .= "&param2=".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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация