dongsu4345 2017-01-21 09:52
浏览 27

如何用简单的html dom解析器修复这个空白区域?

i have find a php snippet that i modify for my need ,it use simple html dom for parse data from a webpage

here is a part of my code

$html = new simple_html_dom();
$html->load_file($page);

$items = $html->find('ul[class=history_list]');  

foreach($items as $post) {
$items = $post->find('li[class=sub_pop_headline]');
$title=$items->plaintext;

foreach($items as $post) {
# remember comments count as nodes
$items_data =  strip_tags($post);

echo $query = "INSERT INTO `mysqltable` ( `entry_id`,`domain_id`, `keyword`, `data`) VALUES  ('',1, '$items_data', 'a:1:{s:11:\"{%KEYWORD%}\";s:11:\"$items_data\";}')";

$query_submit = mysqli_query($conn,$query);

the data are fetched (it work) but they are inserted with a lot of blank space into the sql table

here is what should look like the entry columns keyword & data

my fetched title | a:1:{s:11:"{%KEYWORD%}";s:9:"my fetched title";}

but my code give this as output....

my     fetched              title| a:1:{s:11:"{%KEYWORD%}";s:9:"my     fetched             title";}

as you can see there is a lot of space so this is not correct

thanks you very much for help me , im not really a coder...

  • 写回答

1条回答 默认 最新

  • douwei7471 2017-01-21 10:09
    关注

    Sounds like all you need to do is trim() the title:

    $title = trim($items->plaintext);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line