douhuiwan5141 2016-06-06 10:24
浏览 33

在数据库中保存PHP简单HTML DOM解析器标识符的正确方法

I am trying to save in database PHP Simple HTML DOM Parser indentificators for specific fields and that I call each field indentificators and use them as follows:

$query='select description from ........';
$result = .....;
//-this is how description is saved in the database
// $html->find('div.shortd',0)->outertext();
$row[0]=$html->find('div.shortd',0)->outertext();
$description = $row[0]; - this should be equivalent of:
$description = $html->find('div.shortd',0)->outertext();

but it doesn't work

What format should I save $html->find('div.shortd',0)->outertext(); so after I call it from database to make it work..

Let me explain you briefly what it will be used for: Lets say I have 6000 suppliers. Each of them wish to upload products in my website. I made beta version of crawler which loads specific data from each supplier website so to successfully upload a product I just require the supplier to paste the url in his website of the product he wish to upload. Each website has different structure and now I am facing a problem with this because the structure of each website very vary. Lets say I wish to get img src of the product which may look like:

<div class="aa">
<p>text</p>
<p><img src="../url-to-image"></p>
</div>

so to get it I am doing this:

$image = $html->find('div.aa > p > img');
$image=$image->src;

This works if image is only 1 but to get all images I will have to loop trough images. So the only option for me is to save either:

$image = $html->find('div.aa > p > img');$image=$image->src;

in the database for single image website or similar code but including the loop code.. This is why I need to save it in database and than to load and make this php code working.. I hope now is more clear..

I tried with :

$description = eval($row[0]);

but it doesn't work also I can see in error log this:

syntax error, unexpected end of file in public_html/file.php: eval()'d code on line 1
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 微信会员卡等级和折扣规则
    • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
    • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
    • ¥15 gdf格式的脑电数据如何处理matlab
    • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
    • ¥100 监控抖音用户作品更新可以微信公众号提醒
    • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
    • ¥70 2048小游戏毕设项目
    • ¥20 mysql架构,按照姓名分表
    • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分