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

Posted by feed_sheep on 11/06/90 11:31

<laredotornado@zipmail.com> wrote in message
news:1131133990.080538.174740@f14g2000cwb.googlegroups.com...

> <?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;
> ?>

I can't see how you have it set up, but if a previous page does not pass the
variable $LTON, it will of course equal nothing. Also, you are putting
<?php ?> instead of <?php ?> tags.

This code works:

<?php
$LTON = 1;
$str = "&mine=20&agency_id=234&test=abc";
$search = "/agency_id=\d+/i";
$replace = "agency_id=" . $LTON;
$retVal = preg_replace($search, $replace, $str);
print $retVal;
?>

David

 

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

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