Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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()"/>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
179 views
Welcome To Ask or Share your Answers For Others

1 Answer

You are mixing two different execution paradigms here:

PHP is executed server-side. That means that the server, hosting your code executes it. As a consequence PHP code is usually not visible to clients. The execution of the php code is triggered by a clients request, and the output of the script (e.g. produced by the printf-function) is passed to the client.

Javascript however, is executed client-side. This implies that the cpu of the website visitor is actually used to execute the code. The code is 100% visible to the client. So what you paste within an HTML documents script-tags is executed client side. It is seen by the client. Contrary, PHP code is not meant to be directly pasted within script tags.

These are very generalized statements, that do always hold. However, they should give you a rough sketch. There is a quite nice answer in this thread that should help you for a better distinction. You should certainly learn these basics, before continuing.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...