问题描述
如何制作if语句,检查字符串是否包含正斜杠?
How do i make a if statement which checks if the string contains a forward slash?
$string = "Test/Test";
if($string .......)
{
mysql_query("");
}
else
{
echo "the value contains a invalid character";
}
推荐答案
你可以使用strpos,将确保字符串中有正斜杠但您需要通过等式运行它以确保它不是假的。在这里,您可以使用。简短而简单的代码,完成工作!
You can use strpos, which will make sure there is a forward slash in the string but you need to run it through an equation to make sure it's not false. Here you can use strstr(). Its short and simple code, and gets the job done!
if(strstr($string, '/')){
//....
}
对于那些生活和死亡的人手册,当大海捞针非常大,或针很小时,使用 strstr()
更快,尽管手册说的是。
For those who live and die by the manual, when the haystack is very large, or the needle is very small, it is quicker to use strstr()
, despite what the manual says.
示例:
使用 strpos()
: 0.00043487548828125
Using strpos()
: 0.00043487548828125
使用 strstr()
:0.00023317337036133
Using strstr()
: 0.00023317337036133
这篇关于如果string包含正斜杠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!