1

I am trying to parse html page of Google play and getting some information about apps. Simple-html-dom works perfect, but if page contains code without spaces, it completely ingnores attributes. For instance, I have html code:

<div class="doc-banner-icon"><img itemprop="image"src="https://lh5.ggpht.com/iRd4LyD13y5hdAkpGRSb0PWwFrfU8qfswGNY2wWYw9z9hcyYfhU9uVbmhJ1uqU7vbfw=w124"/></div>

As you can see, there is no any spaces between image and src, so simple-html-dom ignores src attribute and returns only <img itemprop="image">. If I add space, it works perfectly. To get this attribute I use the following code:

foreach($html->find('div.doc-banner-icon') as $e){          
        foreach($e->find('img') as $i){
            $bannerIcon = $i->src;              
        }
}

My question is how to change this beautiful library to get full inner text of this div?

Nolesh
  • 6,848
  • 12
  • 75
  • 112
  • You could use [PHP's DOMDocument](http://php.net/manual/en/class.domdocument.php) instead of Simple HTML Dom Parser. Otherwise just look at this snippet at http://codepad.org/HdUQKx3l, just loading and saving the HTML via DOMDocument adds the spaces you need on Simple HTML Dom Parser. – Rolando Isidoro Jun 20 '13 at 12:56

1 Answers1

1

I just create function which adds neccessary spaces to content:

function placeNeccessarySpaces($contents){
$quotes = 0; $flag=false;
$newContents = '';
for($i=0; $i<strlen($contents); $i++){
    $newContents.=$contents[$i];
    if($contents[$i]=='"') $quotes++; 
    if($quotes%2==0){
        if($contents[$i+1]!== ' ' && $flag==true) {             
            $newContents.=' ';
            $flag=false;
        }           
    }
    else $flag=true;        
}   
return $newContents;
}

And then use it after file_get_contents function. So:

$contents = file_get_contents($url, $use_include_path, $context, $offset);
$contents = placeNeccessarySpaces($contents);

Hope it helps to someone else.

Nolesh
  • 6,848
  • 12
  • 75
  • 112