Reply to Re: Resolving {$var} from within a string...

Your name:

Reply:


Posted by Bocah Sableng on 04/18/07 12:03

On Apr 18, 2:57 pm, Chris Jones <chris...@gmail.com> wrote:

> $eid = $_GET['EID'];
> $href = str_replace("{$eid}","{$eid}",db_result($qry,0,"href");
>

Beware of case-sensitive behaviour of str_replace. Perhaps you should
replace str_replace() with str_ireplace() or just change the variable
name to uppercase. And dollar sign inside double quotes replaced with
its variable value.

$href = str_ireplace("{$eid}", $eid, db_result($qry,0,"href");
or
$href = str_replace("{\$EID}", $eid, db_result($qry,0,"href");

For a better approach, consider using preg_replace() with pattern like
"/\{\\\$EID\}/". Because preg_replace() can accept array as parameter,
so you can replace multiple variables in single step.
Another method is using preg_replace_callback() with reusable callback
function.

HTH

[Back to original 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

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