[英]Using Preg_replace for “…”
I want to replace all the "..." with preg_replace, Example : Hello... => Hello 我想用preg_replace替换所有“...”,例如:Hello ... => Hello
I tryed with : 我尝试过:
$dir = preg_replace('/.../', '', $dir);
But it doesn't work :/ 但它不起作用:/
The dot ( .
) is a special character in regular expressions which matches any single character except a newline (or any character at all if PCRE_DOTALL
is specified). 点 (
.
)是正则表达式中的特殊字符,它匹配除换行符之外的任何单个字符(如果指定了PCRE_DOTALL
,则匹配任何字符)。 If you really want to match a literal .
如果你真的想要匹配一个文字
.
character you'd have to escape it or wrap it in a character class. 您必须将其转义或将其包装在角色类中。
However, for something this simple, there's no need for regular expressions. 但是,对于这么简单的事情,不需要正则表达式。 Just use
str_replace
: 只需使用
str_replace
:
$dir = str_replace('...', '', $dir);
Also note, that a horizontal ellipsis ( …
) is a separate Unicode character from three periods ( ...
). 另请注意, 水平省略号 (
…
)是三个句点( ...
)中的单独Unicode字符。 If you need to handle these as well, it gets kind of tricky since PHP doesn't offer true Unicode support. 如果你还需要处理这些,它会变得有点棘手,因为PHP不提供真正的Unicode支持。 Exactly how you handle it depends on the encoding of
$dir
, but assuming it's UTF-8 encoded, this will remove any horizontal ellipsis characters ( \\xE2\\x80\\xA6
is the UTF-8 encoded form of \…
): 具体如何处理它取决于
$dir
的编码,但假设它是UTF-8编码,这将删除任何水平省略号字符( \\xE2\\x80\\xA6
是\…
的UTF-8编码形式):
$dir = str_replace("\xE2\x80\xA6", '', $dir);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.