Xml问题

mdot 2004-08-08 10:08:06
现在已经利用FILE函数将网页的一部分拿了下来,
但是为了只想拿其中的数据,所以想将变为XML,
之后再用XML拿其中的数据,请问PHP中应该如何做呀?
...全文
240 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
mdot 2004-08-17
  • 打赏
  • 举报
回复
UP
mdot 2004-08-15
  • 打赏
  • 举报
回复
不是拉,我得是用FILE函数取别人得网页,这样做肯定不行得
ice_berg16 2004-08-15
  • 打赏
  • 举报
回复
$str = "<table>
<tr><td>xxx</td></tr>
<tr><td>a</td></tr>
...
</table>";

str_replace("<tr><td>xxx</td></tr>","",$str);
mdot 2004-08-15
  • 打赏
  • 举报
回复
UP
mdot 2004-08-15
  • 打赏
  • 举报
回复
比如,我现在已经用FILE拿了个网页下来,形式如下
<table>
<tr><td>xxx</td></tr>
<tr><td>a</td></tr>
...
</table>
如果我想去掉 <tr><td>xxx</td></tr>这行,而其他数据和表得结构保持不变,那么要如何做呢?
mdot 2004-08-09
  • 打赏
  • 举报
回复
上面的程序输出是:
自行车, 39, 25, 33, 97, 汽车, 1, 2,

但现在可惜的是,我要截取的别人的网页的数据是动态变化的,就想一个奖牌榜那样,其中有些数据是变化,但就麻烦了
xuzuning 2004-08-09
  • 打赏
  • 举报
回复
php提供的串函数就能较好的处理这个问题
<?php
$html =<<< HTML
<table>
<tr >
<td height=20 class=9p><span class=9pbig style1>自行车</span></td>

<td bgcolor=FFFB9C class=red>39</td>

<td bgcolor=FFFB9C class=red>25</td>

<td bgcolor=FFFB9C class=red>33</td>

<td bgcolor=FFFB9C class=red>97</td>
</tr>
<tr>
<td>汽车</td>
<td>1</td>
<td>2</td>
</tr>
</table>
HTML;

$str = str_replace(array("\r\n","</td>","</tr>"),array("",",","\n"),$html);
echo $str = strip_tags($str);
?>


当然转换成xml也是可以的,但要复杂很多!
php4需加载domxml扩展,且处理的文本必须是标准的xml格式
php5的情况要好一些,但是php5毕竟才推出。
Debian 2004-08-09
  • 打赏
  • 举报
回复
php4的xml基于expat,php5则是基于libxml,2者都是相当成熟的产品,
没有什么情况好坏的分别,完全是看php开发者的再包装。
mdot 2004-08-08
  • 打赏
  • 举报
回复
比如
在网页中,有以下代码,那请问如何拿呢?
<table>
<tr >
<td height=20 class=9p><span class=9pbig style1>自行车</span></td>

<td bgcolor=FFFB9C class=red>39</td>

<td bgcolor=FFFB9C class=red>25</td>

<td bgcolor=FFFB9C class=red>33</td>

<td bgcolor=FFFB9C class=red>97</td>
</tr>
〈tr>
<td>汽车</td>
<td>1</td>
<td>2</td>
</tr>
</table>
要取出每种物品的数字,要如何搞?
ice_berg16 2004-08-08
  • 打赏
  • 举报
回复
想拿其中一部分数据也不一定非用XML,
explode + 正则函数基本就可以了

21,893

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧