【发布时间】:2014-01-22 17:24:22
【问题描述】:
好的,我在这个问题上被困了几天......一直在尝试找到有关如何将我的变量传递到 php 代码的 url 并在每次提交表单时更新 url 的答案。但是,我发现的只是如何通过 url 传递变量......因为我觉得我需要一个不同的解决方案,所以我真的无法实现这一点。 所以这是代码,除了将我的 $var 传递到 URL 并重新更新脚本以使用新 URL 运行之外,一切似乎都在工作。
例如,原件目前看起来是这样的:
$html = file_get_html('http://www.championselect.net/champ/{$var}');
我希望有人在表单中输入一个条目,并让 $var 每次都更新。
所以: 假设有人想要搜索“ziggs”或“jinx”,他们会在表单中输入名称,并且表单需要更新脚本以使用新的 $var 运行解析器。
非常感谢所有帮助!
<form action="test.php" method="post">
<input type="text" value="<?php echo $var?>" name="var" />
<input type="submit" value="Send" />
</form>
<?php
$var = $_POST['var'];
echo $var;
// Include the library to use it.
include_once('simple_html_dom.php');
// Get div from site. ... Need to implement user selected queries.
$html = file_get_html('http://www.championselect.net/champ/{$var}');
// Put all of the <a> tags into an array named $result
$result = $html -> find('h2,img[class=CS_Champ_Image],.counterName' );
// Run through the array using a foreach loop and print each link out using echo
foreach($result as $element) {
echo $element." ";}
?>
【问题讨论】: