Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.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 可以使用£;作为preg_替换中的分隔符?_Php_Regex_Preg Replace_Special Characters_Eregi - Fatal编程技术网

Php 可以使用£;作为preg_替换中的分隔符?

Php 可以使用£;作为preg_替换中的分隔符?,php,regex,preg-replace,special-characters,eregi,Php,Regex,Preg Replace,Special Characters,Eregi,我正在将我发现的一个eregi_替换函数转换为preg_替换,但是eregi字符串包含键盘上的每个字符。所以我试着用英镑作为分隔符。。它目前正在工作,但我想知道它是否可能因为是非标准字符而导致问题 这里是埃雷吉: function makeLinks($text) { $text = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)', '<a href="\\1">\\1</a>', $

我正在将我发现的一个eregi_替换函数转换为preg_替换,但是eregi字符串包含键盘上的每个字符。所以我试着用英镑作为分隔符。。它目前正在工作,但我想知道它是否可能因为是非标准字符而导致问题

这里是埃雷吉:

function makeLinks($text) {  
$text = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)',
'<a href="\\1">\\1</a>', $text);
$text = eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_\+.~#?&//=]+)',
'\\1<a href="http://\\2">\\2</a>', $text);

    return $text;}
函数makeLinks($text){
$text=eregi_replace(“((f|ht{1}tp://)[-a-zA-Z0-9@:%\+.~#?&/=]+),
“$文本);
$text=eregi_replace(“([[:space:]()[{}])(www.[-a-zA-Z0-9@:%\+.~#?&/=]+),
“\\1”,$text);
返回$text;}
和preg:

function makeLinks($text) {
    $text = preg_replace('£(((f|ht){1}tp://)[-a-zA-^Z0-9@:%_\+.~#?&//=]+)£i',
    '<a href="\\1">\\1</a>', $text);
    $text = preg_replace('£([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_\+.~#?&//=]+)£i',
    '\\1<a href="http://\\2">\\2</a>', $text);

        return $text;
}
函数makeLinks($text){
$text=preg|u replace(“((f|ht){1}tp://)[-a-zA-^Z0-9:%\+.~?&/=]+]i”,
“$文本);
$text=preg_replace(“([:space:[{}])(www.[-a-zA-Z0-9@:%\+.~#?&/=])i',
“\\1”,$text);
返回$text;
}

您将比我们更了解正在解析的数据。就正则表达式而言,它与任何其他ASCII值都没有区别


尽管我不得不问:传统的然后仅仅转义它有什么问题?或者使用一个具有字符范围的类?

您可以使用括号来分隔正则表达式,而不是单个字符,例如:

preg_replace('(abc/def#ghi)i', ...);

这可能比试图找到一个不在表达式中的模糊字符要好。

您可以使用unicode字符,这只是为了确保

\u00A3
注意ereg函数和unicode支持



女王万岁。

是有问题的,因为它不是ASCII字符。它来自拉丁字符集,只有当您的PHP脚本也使用8位表示时才能工作。如果您的文件被编码为UTF-8,那么
将被表示为两个字节。PHP中的PCRE将忽略这一点。(至少我的版本是这样。)

正如@Chris指出的,你可以使用成对的括号字符作为分隔符,但它们必须在整个正则表达式中保持适当的平衡。例如,
…)
(原子组)和
(?这个神圣符号的使用是多么亵渎神明啊!女王应该会听到这件事。我本来是在逃避的(我试图转义分隔符,而不是在表达式中出现分隔符…lol),但我更好奇的是,使用这样的字符是否是个坏主意。