Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8086571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T18:29:44+00:00 2026-06-05T18:29:44+00:00

I’m create a deal agregator but first i need to put xpath into database

  • 0

I’m create a deal agregator but first i need to put xpath into database but before that I need to type xpath and website into my fields to see what result I will get… so some type of xpath validation tool:

Here is my code for type xpath adresses into textfields:

xpathadd.html

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<script src="http://code.jquery.com/jquery-latest.min.js"
        type="text/javascript"></script>

</head>

<body>
<script>
addToDatabase = function() {
    alert("addToDatabase called");
    $.post("generatingxpath.php", {
        websource: $('#websource').val(),
        links: $('#links').val(),
        title: $('#title').val(),
        image: $('#image').val(),
        discount: $('#discount').val(),
        price: $('#price').val(),
        description: $('#description').val(),
        coordinates: $('#coordinates').val()
    }, function(data) {
        $("#result").html(data);
    });
};​
</script>
<form name="form1" method="post" action="generatingxpath.php">

  <p>
    <label for="websource"></label>
    Web source:
    <input name="websource" type="text" id="websource" size="70">
  is:</p>
  <p>

    <label for="links"></label>
    Links:
    <input name="links" type="text" id="links" size="77">
    OK!
  </p>
  <p>

    <label for="title"></label>
    Title:
    <input name="title" type="text" id="title" size="78">
  is:</p>
  <p>

    <label for="image"></label>
    Image:
    <input name="image" type="text" id="image" size="76">
  show:</p>
  <p>

    <label for="discount"></label>
    Disscount:
    <input name="discount" type="text" id="discount" size="72">
  is:</p>
  <p>

    <label for="price"></label>
    Price:
    <input name="price" type="text" id="price" size="77">
  is:</p>
  <p>

    <label for="description"></label>
    Desription:
    <input name="description" type="text" id="description" size="72">
  is:</p>
  <p>

    <label for="coordinates"></label>
    Coordinates:
    <input name="coordinates" type="text" id="coordinates" size="70">
  lat,lng is:</p>
  <p>
    <input type="submit" name="Submit" id="Submit" value="Preview">
or
<input type="submit" name="Add to database" id="Add to database" value="Add To Database">
<a href="javascript:addToDatabase();">Add to database</a>
  </p>
  <p>&nbsp;</p>
</form>
    <div id="result"></div>
</body>
</html>​

and generatingxpath.php

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<title>GENERATING XPATH</title>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

</head>



<body>

<?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->loadHTMLFile($websource); 

$xpath = new DOMXPath($dom); 

$entries = $xpath->query($links);

$output = array(); 

$i = 1;

foreach($entries as $e) {   

  $dom2 = new DOMDocument(); 

  @$dom2->loadHTMLFile($websource . $e->textContent); 

  $xpath2 = new DOMXPath($dom2); 

  $data = array();

  $data['websource']= ($websource . $e->textContent);

  $data['title'] = trim($xpath2->query($title)->item(0)->textContent); 

  $data['description'] = trim($xpath2->query($description)->item(0)->textContent); 

  $data['image'] = trim($xpath2->query($image)->item(0)->textContent); 

  $string = $xpath2->query($coordintes)->item(1)->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->query($disscount)->item(0)->textContent);
    $data['price'] = trim($xpath2->query($price)->item(0)->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; 



} 



?>

</body>

</html>

but I get only Warning: Invalid argument supplied for foreach() in /home/pluspon/public_html/test/generatingxpath.php on line 67
??? WHY? where is problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T18:29:45+00:00Added an answer on June 5, 2026 at 6:29 pm

    The value of $_POST["links"] does not match in the DOM/XML!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I used javascript for loading a picture on my website depending on which small

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.