Reply to Re: replace

Your name:

Reply:


Posted by Justin Koivisto on 04/25/06 19:15

alexjaquet@gmail.com wrote:
> Hi,
>
> I'm looking for a way to replace some variables for example in perl I
> do :
>
> #replace all $LABEL variables with corresponding values from $SERVER
> var
> s/\$LABEL{'([\w]+)'}/ exists $SERVER{$1} ? $SERVER{$1} : $1 /eg;
> #replace $LANG var with the value of $lang
> s/\$LANG/$lang/g;
>

What is the context of this? Are you talking about replacing literal
"$LABEL{'label_name'}" with the value of _$SERVER['label_name'] in a string?

If so, you could try this where $s is the string that has the content
that will need the replacing:

<?php
$pattern='/\$LABEL\{\'([\w]+)\'\}/s';
if(preg_match_all($pattern,$s,$m)){
$matches=count($m[0]);
for($i=0;$i<$matches;$i++){
if(isset($_SERVER[$m[1][$i]])){
$s=str_replace($m[0][$i],$_SERVER[$m[1][$i]],$s);
}else{
$s=str_replace($m[0][$i],$m[1][$i],$s);
}
}
}
?>

--
Justin Koivisto, ZCE - justin@koivi.com
http://koivi.com

[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

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