Note that there are some explanatory texts on larger screens.

plurals
  1. POXpath and html form action post php
    primarykey
    data
    text
    <p>I'm trying to create some helper tool for me. Becouse i create a deal agregator and i need to put xpath into my database but fisrt i need to create some tool to help me with validation.</p> <p>I have a html file where i need to put xpath and then with action i go to generatingxpath.php file where i need to see what i get with xpath that i write. so...</p> <pre><code>&lt;!DOCTYPE HTML&gt; &lt;html&gt; &lt;head&gt; &lt;meta charset="utf-8"&gt; &lt;title&gt;Untitled Document&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;form name="form1" method="post" action="generatingxpath.php"&gt; &lt;p&gt; &lt;label for="websource"&gt;&lt;/label&gt; Web source: &lt;input name="websource" type="text" id="websource" size="70"&gt; is:&lt;/p&gt; &lt;p&gt; &lt;label for="links"&gt;&lt;/label&gt; Links: &lt;input name="links" type="text" id="links" size="77"&gt; OK! &lt;/p&gt; &lt;p&gt; &lt;label for="title"&gt;&lt;/label&gt; Title: &lt;input name="title" type="text" id="title" size="78"&gt; is:&lt;/p&gt; &lt;p&gt; &lt;label for="image"&gt;&lt;/label&gt; Image: &lt;input name="image" type="text" id="image" size="76"&gt; show:&lt;/p&gt; &lt;p&gt; &lt;label for="disscount"&gt;&lt;/label&gt; Disscount: &lt;input name="disscount" type="text" id="disscount" size="72"&gt; is:&lt;/p&gt; &lt;p&gt; &lt;label for="price"&gt;&lt;/label&gt; Price: &lt;input name="price" type="text" id="price" size="77"&gt; is:&lt;/p&gt; &lt;p&gt; &lt;label for="description"&gt;&lt;/label&gt; Desription: &lt;input name="desription" type="text" id="description" size="72"&gt; is:&lt;/p&gt; &lt;p&gt; &lt;label for="coordinates"&gt;&lt;/label&gt; Coordinates: &lt;input name="coordinates" type="text" id="coordinates" size="70"&gt; lat,lng is:&lt;/p&gt; &lt;p&gt; &lt;input type="submit" name="Submit" id="Submit" value="Preview"&gt; or &lt;input type="submit" name="Add to database" id="Add to database" value="Add To Database"&gt; &lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>and my php file is:</p> <pre><code>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;GENERATING XPATH&lt;/title&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"&gt; &lt;/head&gt; &lt;body&gt; &lt;?php function curl($url){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_ENCODING, "gzip"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $data = curl_exec($ch); curl_close($ch); return $data; } libxml_use_internal_errors(true); $websource = $_POST["websource"]; $links = $_POST["links"]; $title = $_POST["title"]; $image = $_POST["image"]; $disscount = $_POST["disscount"]; $price = $_POST["price"]; $description = $_POST["description"]; $coordinates = $_POST["coordinates"]; //start generating xpath script $dom = new DOMDocument(); @$dom-&gt;loadHTMLFile($websource); $xpath = new DOMXPath($dom); $entries = $xpath-&gt;query($links); $output = array(); $i = 1; foreach($entries as $e) { $dom2 = new DOMDocument(); @$dom2-&gt;loadHTMLFile($websource . $e-&gt;textContent); $xpath2 = new DOMXPath($dom2); $data = array(); $data['websource']= ($websource . $e-&gt;textContent); $data['title'] = trim($xpath2-&gt;query($title)-&gt;item(0)-&gt;textContent); $data['description'] = trim($xpath2-&gt;query($description)-&gt;item(0)-&gt;textContent); $data['image'] = trim($xpath2-&gt;query($image)-&gt;item(0)-&gt;textContent); $string = $xpath2-&gt;query($coordintes)-&gt;item(1)-&gt;textContent; preg_match_all('#(([0-9-]+){1,3}.([0-9]+))#is', $string, $matches); $data['lat']=$matches[1]; $data['lng']=$matches[2]; $data['disscount'] = trim($xpath2-&gt;query($disscount)-&gt;item(0)-&gt;textContent); $data['price'] = trim($xpath2-&gt;query($price)-&gt;item(0)-&gt;textContent); //print to see that all is fine or need to change some xpath direction echo $data['websource']; echo $data['links']; echo $data['title']; echo $data['image']; echo $data['disscount']; echo $data['price']; echo $data['lat']; echo $data['lng']; echo $data['description']; $output[] = $data; } ?&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>I get several errors first in 67 line. for each ... etc.</p> <p>is there some easy solution to i get result on the same page, so to get text from some website with xpath but to show on html page... ajax??? or something?</p> <p>What is the best solution for my problem? How to solve this?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload