0

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...

  • Possible duplicate of [Remove excess whitespace from within a string](http://stackoverflow.com/questions/1703320/remove-excess-whitespace-from-within-a-string) – Rajdeep Paul Jan 21 '17 at 10:03
  • thank you Rajdeep , but none of these solution worked for me , i tried all preg_replace listed from here http://stackoverflow.com/questions/1703320/remove-excess-whitespace-from-within-a-string – Pierre Demarque Jan 21 '17 at 13:45

1 Answers1

0

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

$title = trim($items->plaintext);
Mark Berube
  • 206
  • 3
  • 11