I'm trying to parse this HTML from remote url using Simple HTML DOM Parser:
<div class="_5pbx userContent _3ds9 _3576" data-ft="data-ft='{"tn":"K"}'">
<p>text to be parsed</p>
<p>the rest of text</p>
</div>
The PHP snipe I used is as the following:
include (getdomain . "/lib/simple_html_dom.php");
$html = new simple_html_dom();
$get = file_get_contents("http://localhost/get/d.json");
$html->load($get);
foreach ($html->find('div[class=_5pbx userContent _3ds9 _3576]') as $link) {
if(isset($link)){
echo $link->plaintext ;
}
}
But it didn't work, I'm aware of the <p> tag and I tried to add if statement for that but still didn't work, as the following:
include (getdomain . "/lib/simple_html_dom.php");
$html = new simple_html_dom();
$get = file_get_contents("http://localhost/get/d.html");
$html->load($get);
foreach ($html->find('div[class=_5pbx userContent _3ds9 _3576]') as $link) {
if(isset($link)){
foreach($link->find('p') as $tag)
{
echo $tag->plaintext ;
}
}
}
But all didn't work :(
Any idea?
getdomaina defined symbol in your system? Or is it a function?echo $html->find('title',0)->plaintext;, but for the class with multiple classes it fails.camelCaseand I'm pretty sure that a method or function always requires()if said method/function requires no additional parameters - if it's a defined constant then I would useCAPSCASE, not because you want to shout at other developers, but to alert them thatgetdomainis a constant. Otherwise it looks like a typo, either a variable with a missing$at the start, or a function/method with missing()- finallygetdomainsounds like agetterso how would one set it?