php 检查字符串是否包含逗号
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37155382/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 01:05:23 来源:igfitidea点击:
Check if string contains commas
提问by Sumit Nair
Check if string contains commas in it? i have a sting how can i check it it contains comma separated values or not
检查字符串中是否包含逗号?我有一个刺,我如何检查它是否包含逗号分隔值
example : $search=6,7,8,9,10
回答by Maninderpreet Singh
php function strpos
return position of string if it's not false or -1 then your string contain character.
php 函数strpos
返回字符串的位置,如果它不是 false 或 -1 那么你的字符串包含字符。
$searchForValue = ',';
$stringValue = '115,251';
if( strpos($stringValue, $searchForValue) !== false ) {
echo "Found";
}
回答by Arshid KV
You can try with preg_mathor strposmethods.
您可以尝试使用preg_math或strpos方法。
$re = '/,/m';
$str = 'Hi...1,2,3,4';
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
// Print the entire match result
var_dump($matches);