al********@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 -
ju****@koivi.com http://koivi.com