Reputation: 75
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;
}
?>
Upvotes: 6
Views: 7423
Reputation: 5766
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);
Upvotes: 5