0

I want to capture the value of: <div id="result"></div> which keep on changing, into a php variable $foo and then insert it into the database. My codes:

<?php 
include('config.inc');
$foo = '<div id="result"></div>';
$query= "INSERT INTO register(name) VALUES('$foo')";
echo $foo;
mysql_query($query) or die('An Error occurred' .mysql_error());
?>

The error: Value inserted into the db is:

<div id="result"></div>

, not the value that user has enter... Any help please?

4

2 回答 2

2

试试这个,使用 php DomDocument 类。http://www.php.net/manual/en/class.domdocument.php

$dom = new DOMDocument();

$dom->loadHTML($html);

$xpath = new DOMXPath($dom);
$divContent = $xpath->query('//div[id="product_list"]');
于 2013-10-10T14:53:37.260 回答
1

此代码将返回所有具有 id 结果的 div 的内容

$value=preg_match_all('/<div id=\"result\">(.*?)<\/div>/s',$foo,$estimates);
print_r($estimates);

测试这个: -

 $value=preg_match_all('/<div id=\"result\">(.*?)<\/div>/s',$foo,$estimates); $query= "INSERT INTO register(name) VALUES('".$estimates[0]."')";
于 2013-10-10T15:15:20.167 回答