Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在预更换内使用strtr?_Php_Preg Replace_Strtr - Fatal编程技术网

Php 在预更换内使用strtr?

Php 在预更换内使用strtr?,php,preg-replace,strtr,Php,Preg Replace,Strtr,我想将preg\u replace()中的preg\u replace()与strtr()匹配重新格式化。 可能吗 我做了以下工作: $array = array("#" => "_", "/" => "-"); $output = preg_replace($regex, '<span>'.strtr('$0', $array).'</span>', $input); $array=array(“#“=>”、“/”=>“-”); $output=preg_

我想将preg\u replace()中的
preg\u replace()
strtr()
匹配重新格式化。 可能吗

我做了以下工作:

$array = array("#" => "_", "/" => "-");
$output = preg_replace($regex, '<span>'.strtr('$0', $array).'</span>', $input);
$array=array(“#“=>”、“/”=>“-”);
$output=preg_replace($regex,“.strtr($0,$array)。”,$input);
在我的示例中,Z#(对应于我的
preg_replace
match,
strtr
中的$0)应该变成Z#,但什么也没有发生

谢谢大家!


注意$正则表达式是一个正则表达式,与$input的某些部分匹配,它可以工作。

使用e-修饰符:

$output = preg_replace('/$regex/e', '"<span>".strtr("$0", $array)."</span>"', $input);
$output=preg_replace('/$regex/e','.strtr($0',$array)。'',$input);

这是不可能的,因为
'0'
内部
strtr
不是
preg\u replace
替换字符串的一部分,只是
strtr
草堆的一部分,所以它实际上是
'0'
…你为什么不把
strtrtrtr
放在
preg\u replace
之外呢?不,不,不,不要这样做。
e
修改器基本上将
preg\u replace()
转换为
eval()
。不,不,不…不要每次有人听到关于“eval”的东西时都读这些短语谢谢Molle博士,但这样做我会得到以下错误:
Parse error:syntax error,unexpected'对我有用:。在外部使用单引号很重要。当您切换引号时,可以看到不同之处:太棒了,它可以工作!我有一个评估错误,因为一个坏的单/双引号组合。谢谢!