如何在PHP中解析并在数据库中存储? [英] How to Parse in PHP and Storing in Database?

查看:73
本文介绍了如何在PHP中解析并在数据库中存储?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从此页面解析了匹配项:

I Parsed the Matches from this Page:

$html = file_get_html('http://www.espncricinfo.com/rankings/content/current/page/211271.html');
$es = $html->find('table td[class=left]');

如果我打印值:

echo "Matches: $es[37]";

工作正常:

Matches: 48

我想将该值存储在数据库中

I want to store that Value in Data base:

UPDATE Table SET Column1=($es[37]) WHERE Column2='123';

它不起作用.如果数据类型为INT,则存储为0;如果数据类型为VARCHAR,则存储为table td[class=left].

Its not working. If the data type is INT it Storing as '0' and if the data type is VARCHAR, then it storing as table td[class=left].

我如何存储它?

推荐答案

您要$es->innertext而不是$es.
尝试以下代码:

You want $es->innertext and not $es.
Try this code:

$html =file_get_html('http://www.espncricinfo.com/rankings/content/current/page/211271.html');
$es = $html->find('td[class=left]',37);
$query = "UPDATE my_table SET Column1='".$es->innertext."' WHERE Column2=123;";

这篇关于如何在PHP中解析并在数据库中存储?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆