ADM*_*ADM 1 php regex match preg-match
我正在尝试使用preg_match解析以下内容:
2020|9 digits number|date hour|word|word
Run Code Online (Sandbox Code Playgroud)
举个例子:
2020|123456789|01/04/2011 09:09:37|Basketball|sms
Run Code Online (Sandbox Code Playgroud)
我正在做:
$regex = '2020|/[0-9]+\|[a-zA-Z]+\|[0-9]{2}\/[0-9]{2}\/[0-9]{4}.*/';
return !(preg_match($regex,$value));
Run Code Online (Sandbox Code Playgroud)
但是我收到了错误Delimiter must not be alphanumeric or backslash
,而且我没有接近它.
你能帮我个忙吗?
如果|
是您的分隔符,并且数据始终按您描述的方式构建,那么为什么不使用explode()
呢?
$array = explode ("|", $value);
echo $array[0]; // Will output "2020"
echo $array[1]; // Will output "123456789"
Run Code Online (Sandbox Code Playgroud)
为了使其可靠地工作,没有列必须包含"|" 作为内容角色.但你也有正则表达式的限制.
如果您正在解析像这样构建的整个文件,请查看fgetcsv()
.
归档时间: |
|
查看次数: |
614 次 |
最近记录: |