开发者

Preg match full stop

I am trying to run a preg_match on every file that contains a full stop with it.

<?php 

$furl = "Maid with the Flaxen Hair.mp3";开发者_运维知识库

if (preg_match("/./i", $furl)) { 

echo "Contains full stop";

}

?>

Can someone please help???


Alternate and also fast then preg_match

if (strpos($furl, '.') !== false)
{
 echo "Contains full stop";
}


<?php 

$furl = "Maid with the Flaxen Hair.mp3";

if (preg_match("/\./", $furl)) { 

echo "Contains full stop";

}

?>

In a regexp, '.' matches any character. If you want to limit it to a real '.', escape it with '\'.

You also don't need the /i, since there are no letters involved.


. in regular expressions means "Match anything". Escape it thusly \.. (Though strpos is probably faster in this case)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜