前置: $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;
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.