【发布时间】:2012-09-26 02:08:33
【问题描述】:
我这几天有问题 :s ... 我试图在字符串中获取一些变化的数据,字符串是这样的:
<docdata>
<!-- News Identifier -->
<doc-id id-string ="YBY15349" />
<!-- Date of issue -->
<date.issue norm ="2012-09-22 19:52" />
<!-- Date of release -->
<date.release norm ="2012-09-22 19:52" />
</docdata>
我需要的只是 "2012-09-22 19:52" 中的 date ,该字符串存储在某种类型的 xml 中,由方式。所以我不能使用普通的 xml 解析器,我已经加载/读取文件来更改一些字符集
$fname = $file;
$fhandle = fopen($fname,"r");
$content = fread($fhandle,filesize($fname));
str_replace("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>", $content);
etc..
这项工作就像一个魅力,但我无法使用字符串。 我尝试使用 preg_match_all 但我无法正确处理。 它有一个简单的方法来搜索这个值
<date.issue norm ="2012-09-22 19:52" />
只获取变量中的日期?
在此先感谢,对不起我的英语。
【问题讨论】:
-
file_get_contents对于您的前 3 行更容易。
标签: php xml arrays parsing tags