开发者

Preg match full stop

开发者 https://www.devze.com 2023-03-17 14:54 出处:网络
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\";开发者_运维知识库

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

精彩评论

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