我想捕获持续改变的<div id="result"></div>
的值,进入php变量 $ foo ,然后将其插入数据库。 我的代码:
<?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());
?>
错误: 插入数据库的值为:
<div id="result"></div>
,而不是用户输入的值... 有什么帮助吗?
答案 0 :(得分: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"]');
答案 1 :(得分:1)
此代码将返回id为result
的所有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]."')";