PHP将文本转换为变量(html dom)

PHP将文本转换为变量(html dom),php,simple-html-dom,Php,Simple Html Dom,我需要将字符串转换为变量。字符串通过参数传递给函数 public function get($url, $mainclass, $title){ include_once('simple_html_dom.php'); $html = new simple_html_dom(); $html->load_file($url); foreach($html->find(".$mainclass") as $div){ $title_

我需要将字符串转换为变量。字符串通过参数传递给函数

public function get($url, $mainclass, $title){
    include_once('simple_html_dom.php');

    $html = new simple_html_dom();
    $html->load_file($url);

    foreach($html->find(".$mainclass") as $div){
        $title_ = $title;
        /*
               $title_ should get
               $title_ = $div->children(0)->alt;
            */
        return $title;
    }
}
因此,要调用函数:

echo $crawl->get("url","description", '$div->children(0)->alt'); 
这可能吗?如果是,怎么做


我需要传递整个
$div->..
,而不仅仅是标签
alt
,因为它可以不同。有时我可以传递
$div->children(0)->children(2)->children(1)->alt
删除
$div->children(0)->alt
周围的单引号。我没有初始化$div。。这意味着它将给出错误。您可以使用
eval
,但这是非常不鼓励的<代码>$title\=eval($title)谢谢,但我确实认为我的方法不是最好的。我已经更改了代码。