I am new with PHP and i have a little problem.
How can I search with variable with simple html dom parser? My id is "ti" and there are several same named divs. I only need the first one. The code works if i put ti instead of $variable
to code.
thanks!
<?php
$variable = "ti"
include_once 'simple_html_dom.php';
$html = file_get_html('http://myurl.here');
$ret = $html->find('div[id=$variable]', 0);
if ($ret) {
echo $ret->innertext;
}
?>
You need to use double quotation marks (i.e. "
instead of '
) to embed variables in PHP strings, like this:
$ret = $html->find("div[id=$variable]", 0);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With