Home  >  Article  >  Backend Development  >  提取TXT里数据出错

提取TXT里数据出错

WBOY
WBOYOriginal
2016-06-23 13:53:46801browse

$file = '15.txt';  

$content = file_get_contents($file);  
$array = explode("\r\n", $content);  
 for($i=0; $i  {  
preg_match("/\杰\德(.*)\'/U",$array[$i],$dss);
echo $dss[$i];
 } 
想提取文本里所有的 “杰德”到'之间的数据,我这样写对吗,怎么都提不出来呢


回复讨论(解决方案)

preg_match("/杰德(.*)'/U", $array[$i], $dss);

一样啊提取不出来

没有符合条件的,自然就取不出来

你 echo $dss[$i]; 就是有也打印不出来

preg_match("/杰德(.*)'/U", $array[$i], $dss);


这个妥妥的可以哇,要内容里面有然后输出的时候你的输出方式不对,要输出的为$dss[2]的数据,才是你想要的数据,你用个$i能输出就奇怪了。

1、print_r($array); 看看数据是否正常

2、输出改为:
echo $dss[1];  

Statement:
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