在php中反转正则表达式
假设我有这个函数:在php中反转正则表达式,php,regex,function,reverse,inverse,Php,Regex,Function,Reverse,Inverse,假设我有这个函数: function f($string){ $string = preg_replace("`\[.*\]`U","",$string); $string = preg_replace('`&(amp;)?#?[a-z0-9]+;`i','-',$string); $string = htmlentities($string, ENT_COMPAT, 'utf-8'); $string = preg_replace( "`&([a
function f($string){
$string = preg_replace("`\[.*\]`U","",$string);
$string = preg_replace('`&(amp;)?#?[a-z0-9]+;`i','-',$string);
$string = htmlentities($string, ENT_COMPAT, 'utf-8');
$string = preg_replace( "`&([a-z])(acute|uml|circ|grave|ring|cedil|slash|tilde|caron|lig|quot|rsquo);`i","\\1", $string );
$string = preg_replace( array("`[^a-z0-9]`i","`[-]+`") , "-", $string);
return $string;
}
如何反转此功能…即。我应该如何编写函数fReverse(),使我们具有以下内容:
$s = f("some string223---");
$reversed = fReverse($s);
echo $s;
和输出:一些字符串223---
f
有损。不可能找到确切的反面。例如,“some string223----”
和“some string223----”
都提供相同的输出(请参阅)
然而,我们可以找到
f
的预映像。f
的5个替换项为:
[
和]
之间的所有内容
,和#123代码>和编码实体,如&;lt代码>到连字符-
为什么不将第一个字符串保存在某个地方?关键是,您可以从url动态地反转这些字符串,这样就无法达到目的
function fReverse($string) {
return html_entity_decode($string, ENT_COMPAT, 'utf-8');
}