如果string包含正斜杠 [英] If string contains forward slash

查看:1240
本文介绍了如果string包含正斜杠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何制作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,将确保字符串中有正斜杠但您需要通过等式运行它以确保它不是假的。在这里,您可以使用 strstr()。简短而简单的代码,完成工作!

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包含正斜杠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆