Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP simple html dom parser div id with variable

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; 
}
?>
like image 850
user3155139 Avatar asked Jan 09 '14 09:01

user3155139


1 Answers

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);
like image 125
Peter Bloomfield Avatar answered Oct 04 '22 20:10

Peter Bloomfield