抓取代码在 php 中不起作用以形成控件 [英] Scraping code not working in php to form controls

查看:26
本文介绍了抓取代码在 php 中不起作用以形成控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将网页内容抓取到我的表单控件中,没有函数我正在获取输出,但是当我创建函数并分配给按钮单击事件以在文本框中显示输出时,它不起作用,让我知道我在哪里搞砸了.

I am trying to scrape webpage content to my form controls, Without function i am getting output, but when i created function and assigned to button click event to display the output in textbox its not working, let me know where i am messed.

<script type="text/javascript">
function Assign()
{
$html = file_get_contents("http://geoportaal.maaamet.ee/url/xgis-ky.php?ky=79401:006:0812");
preg_match_all('(<li.*?>.*?</li>)', $html, $matches);
$one=$matches[0][0];
document.getElementById("OutputField").value = $one;
}
</script>
<input id="OutputField" type="text" style="width:200px"/>
<input type="button" value="Assign Value" onclick="Assign()"/>

推荐答案

首先,你必须分离你的 html、php、javascript 代码.我更改了您的代码,您可以尝试一下.如果您以正确的方式使用它,它将起作用.

Firstly, you must separate your html, php, javascript code. I changed your code and you can try it. If you use it in right way it will work.

<?php
$html = file_get_contents("http://geoportaal.maaamet.ee/url/xgis-ky.php?ky=79401:006:0812");
preg_match_all('(<li.*?>.*?</li>)', $html, $matches);
$one=$matches[0][0];
?>

<script type="text/javascript">
    function Assign() {
        document.getElementById("OutputField").value = "<?=$one?>";
    }
</script>

<input id="OutputField" type="text" style="width:200px"/>
<input type="button" value="Assign Value" onclick="Assign()"/>

希望对你有帮助.你必须学习和学习.;-)

I hope it was helpful for you. You must study and study. ;-)

这篇关于抓取代码在 php 中不起作用以形成控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆