Home > Backend Development > PHP Tutorial > php intercepts characters before comma

php intercepts characters before comma

WBOY
Release: 2016-07-29 09:06:22
Original
2238 people have browsed it

前置:
$foo = 'aaaaaa,vvvvvv,ccccc,dddd';
if(($index = strstr($foo,',') !== false):

答案1:用正则-》
$Regex = '#([^,]+)#is';
preg_match($Regex,$foo,$result);
echo $result[1]; //输出结果:aaaaaa
答案2:用分割字符串-》
$foo = explode(',',$foo);
echo $foo[0];  //输出结果:aaaaaa
答案3:用寻找和截取字符串-》
echo substr($foo,0,$index);   //输出结果:aaaaaa
 
后置:
:endif;
Copy after login

The above introduces PHP to intercept the characters before the comma, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template