使用php从文本文件中提取值

我正在尝试使用preg_match_all()从以下行中提取日期和#之间的价​​格44,380.86。日期是2015年1月1日将是动态的,有人可以告诉我如何完成它吗? / p>

start on Jan 1,2015 44,380.86 # of count: 15 tc

wuyeyou0773 回答:使用php从文本文件中提取值

您可以使用此正则表达式(regex explanation):

start on\s[A-Za-z]+\s[1-9]+,\s[0-9]+\s+(.*?)\s+#

示例代码:

<?php
preg_match_all(
    "/start on\s[A-Za-z]+\s[1-9]+,\s[0-9]+\s+(.*?)\s+#/","start on Jan 1,2015                                 44,380.86    # of count: 15 tc",$matches
);

var_dump($matches);
,

我认为这应该可以解决您的其他更改问题:

preg_match_all("(\S+(?:\s\S+)*?)","Your string",$matches);

对于您的问题,您可以使用:

preg_match_all("(\S+(?:\s\S+)*?)",$matches);
echo $matches[5];

此正则表达式使用空格来解析您的字符串,因此当您更改字符串时,只需将$matches的索引从5编辑到您想要的

本文链接:https://www.f2er.com/3154609.html

大家都在问