Search Results

Search found 30 results on 2 pages for 'domxpath'.

Page 1/2 | 1 2  | Next Page >

  • PHP's DOMXPath is stripping out my tags inside the matched text.

    - by Mint
    I asked this question yesterday, and at the time it was just what I needed, but while working with some live data I discovered that is wasn't quite doing what I expected. http://stackoverflow.com/questions/2571232/parse-html-with-phps-html-domdocument I gets the data from the HTML page, but then it also strips out all the HTML tags inside the captured block of text, which isn't what I want. (I might wan't to take some of the tags out, but not all, and this can be done later)

    Read the article

  • PHP XPath - how to get value from result

    - by LeeTee
    I have the followng XML file from Ebay <GeteBayDetailsResponse xmlns="urn:ebay:apis:eBLBaseComponents"><Timestamp>2012-07-04T12:02:14.541Z</Timestamp><Ack>Success</Ack><Version>779</Version><Build>E779_INTL_BUNDLED_14986004_R1</Build><SiteDetails><Site>US</Site><SiteID>0</SiteID><DetailVersion>1</DetailVersion><UpdateTime>2009-07-09T10:48:17.000Z</UpdateTime></SiteDetails><SiteDetails><Site>Canada</Site><SiteID>2</SiteID><DetailVersion>1</DetailVersion><UpdateTime>2009-07-09T10:48:17.000Z</UpdateTime></SiteDetails><SiteDetails><Site>UK</Site><SiteID>3</SiteID><DetailVersion>1</DetailVersion><UpdateTime>2009-07-09T10:48:17.000Z</UpdateTime></SiteDetails><SiteDetails><Site>Germany</Site><SiteID>77</SiteID><DetailVersion>1</DetailVersion><UpdateTime>2009-07-09T10:48:17.000Z</UpdateTime></SiteDetails><SiteDetails><Site>Australia</Site><SiteID>15</SiteID><DetailVersion>1</DetailVersion><UpdateTime>2009-07-09T10:48:17.000Z</UpdateTime></SiteDetails><SiteDetails><Site>France</Site><SiteID>71</SiteID><DetailVersion>1</DetailVersion><UpdateTime>2009-07-09T10:48:17.000Z</UpdateTime></SiteDetails><SiteDetails><Site>eBayMotors</Site><SiteID>100</SiteID><DetailVersion>1</DetailVersion><UpdateTime>2009-07-09T10:48:17.000Z</UpdateTime></SiteDetails><SiteDetails><Site>Italy</Site><SiteID>101</SiteID><DetailVersion>1</DetailVersion><UpdateTime>2009-07-09T10:48:17.000Z</UpdateTime></SiteDetails><SiteDetails><Site>Netherlands</Site><SiteID>146</SiteID><DetailVersion>1</DetailVersion><UpdateTime>2009-07-09T10:48:17.000Z</UpdateTime></SiteDetails><SiteDetails><Site>Spain</Site><SiteID>186</SiteID><DetailVersion>1</DetailVersion><UpdateTime>2009-07-09T10:48:17.000Z</UpdateTime></SiteDetails><SiteDetails><Site>India</Site><SiteID>203</SiteID><DetailVersion>1</DetailVersion><UpdateTime>2009-07-09T10:48:17.000Z</UpdateTime></SiteDetails><SiteDetails><Site>HongKong</Site><SiteID>201</SiteID><DetailVersion>1</DetailVersion><UpdateTime>2009-07-09T10:48:17.000Z</UpdateTime></SiteDetails><SiteDetails><Site>Singapore</Site><SiteID>216</SiteID><DetailVersion>1</DetailVersion><UpdateTime>2009-07-09T10:48:17.000Z</UpdateTime></SiteDetails><SiteDetails><Site>Malaysia</Site><SiteID>207</SiteID><DetailVersion>1</DetailVersion><UpdateTime>2009-07-09T10:48:17.000Z</UpdateTime></SiteDetails><SiteDetails><Site>Philippines</Site><SiteID>211</SiteID><DetailVersion>1</DetailVersion><UpdateTime>2009-07-09T10:48:17.000Z</UpdateTime></SiteDetails><SiteDetails><Site>CanadaFrench</Site><SiteID>210</SiteID><DetailVersion>1</DetailVersion><UpdateTime>2009-07-09T10:48:17.000Z</UpdateTime></SiteDetails><SiteDetails><Site>Poland</Site><SiteID>212</SiteID><DetailVersion>1</DetailVersion><UpdateTime>2009-07-09T10:48:17.000Z</UpdateTime></SiteDetails><SiteDetails><Site>Belgium_Dutch</Site><SiteID>123</SiteID><DetailVersion>1</DetailVersion><UpdateTime>2009-07-09T10:48:17.000Z</UpdateTime></SiteDetails><SiteDetails><Site>Belgium_French</Site><SiteID>23</SiteID><DetailVersion>1</DetailVersion><UpdateTime>2009-07-09T10:48:17.000Z</UpdateTime></SiteDetails><SiteDetails><Site>Austria</Site><SiteID>16</SiteID><DetailVersion>1</DetailVersion><UpdateTime>2009-07-09T10:48:17.000Z</UpdateTime></SiteDetails><SiteDetails><Site>Switzerland</Site><SiteID>193</SiteID><DetailVersion>1</DetailVersion><UpdateTime>2009-07-09T10:48:17.000Z</UpdateTime></SiteDetails><SiteDetails><Site>Ireland</Site><SiteID>205</SiteID><DetailVersion>1</DetailVersion><UpdateTime>2009-07-09T10:48:17.000Z</UpdateTime></SiteDetails><UpdateTime>2009-07-09T10:48:17.000Z</UpdateTime></GeteBayDetailsResponse> I need to get the value of node SiteID where the node Site matches whatever variable I pass. The code I have is: $xml_file ='SiteDetails.xml'; $xmlDoc = new DomDocument(); $xmlDoc->load($xml_file); $xpath = new DOMXpath($xmlDoc); $siteIDList = $xpath->query("/GeteBayDetailsResponse/SiteDetails[Site=$site]/SiteID"); var_dump($siteIDList); echo $siteIDList->SiteID; I get the following result: object(DOMNodeList)#11 (0) { } Can anyone help? I want to get a value of 3.

    Read the article

  • dynamic xpath expression

    - by Ferol
    Good day, colleagues! Tell me please, how to make a dynamic xpath-parsing: for example, instead of writing $domXPath-query('//[(@id = "article-id-18")]'); - write something like that $domXPath-query('//[(@id = "article-id-*")]');, because in my case, the site's script generate (every time) a new id for block, that contains article's text? So question, is above.

    Read the article

  • Weblogic 10.3 weblogic.jar classpath issues

    - by user63063
    I am upgrading an old WLS8.1 app to 10.3 (11g) My ant build includes only the new weblogic.jar in the compile classpath and the build runs with no issues but when I include weblogic.jar as a libeary in the IDE (Intellij) i see many unresolved imports (for example: weblogic.xml.xpath.DOMXPath) when I check the weblogic.jar I see that the classes are indeed missing from it. compiling with verbose revealed that by including weblogic.jar in the ant classpath, many other jars in the BEA_HOME/modules are loaded to the classpath as well (for example: com.bea.core.xml.weblogic.xpath_1.4.0.0.jar) Can anyone explain what is going on? How can I fix my IDE classpath - do I need to import all the module-jars? Many of the module jars seems like they are there to support old deprecated weblogic 8 APIs (like: weblogic.xml.xpath.DOMXPath) how can I exclude these modules from my ant build? (I want to expose the APIs I need to upgrade) Thanks, NY

    Read the article

  • PHP5 : Applying a method from an extended class on an object from the original (parent) class.

    - by Glauber Rocha
    Hello, I'm trying to extend two native PHP5 classes (DOMDocument and DOMNode) to implement 2 methods (selectNodes and selectSingleNode) in order to make XPath queries easier. I thought it would be rather straighforward, but I'm stuck in a problem which I think is an OOP beginner's issue. class nDOMDocument extends DOMDocument { public function selectNodes($xpath){ $oxpath = new DOMXPath($this); return $oxpath->query($xpath); } public function selectSingleNode($xpath){ return $this->selectNodes($xpath)->item(0); } } Then I tried to do extend DOMNode to implement the same methods so I can perform an XPath query directly on a node: class nDOMNode extends DOMNode { public function selectNodes($xpath){ $oxpath = new DOMXPath($this->ownerDocument,$this); return $oxpath->query($xpath); } public function selectSingleNode($xpath){ return $this->selectNodes($xpath)->item(0); } } Now if I execute the following code (on an arbitrary XMLDocument): $xmlDoc = new nDOMDocument; $xmlDoc->loadXML(...some XML...); $node1 = $xmlDoc->selectSingleNode("//item[@id=2]"); $node2 = $node1->selectSingleNode("firstname"); The third line works and returns a DOMNode object $node1. However, the fourth line doesn't work because the selectSingleNode method belongs to the nDOMNode class, not DOMNode. So my question: is there a way at some point to "transform" the returned DOMNode object into a nDOMNode object? I feel I'm missing some essential point here and I'd greatly appreciate your help. (Sorry, this is a restatement of my question http://stackoverflow.com/questions/2573820/)

    Read the article

  • Get tag name and value of a given node using XMLReader, DOM, Xpath

    - by rossjha
    I need to query an xml document and then display specific tag values, e.g. forename, surname, group(dept), job_title. I'm using XMLReader as i may need to work with large XML files. I using DomXPath to filter the data, but i don't know how to retrieve the nodeName and value for each element. The code below only returns 'member' as the node name? Any help would be appreciated. <?php $reader = new XMLReader(); $reader->open('include/staff.xml'); while ($reader->read()){ switch($reader->nodeType){ case(XMLREADER::ELEMENT): if($reader->localName === 'staff'){ $node = $reader->expand(); $dom = new DomDocument(); $dom->formatOutput = true; $n = $dom->importNode($node, true); $dom->appendChild($n); $xp = new DomXpath($dom); $res = $xp->query("/staff/member[groups='HR']"); } } } echo $res->item(0)->nodeName; echo $res->item(0)->nodeValue; ?>

    Read the article

  • Selectind DOM elements based on attribute content

    - by sameold
    I have several types of <a> in my document. I'd like to select only the <a> whose title attribute begins with the text "more data ..." like <a title="more data *"> For example given the markup below, I'd like to select the first and second <a>, but skip the third because title doesn't begin with more data, and skip the 4th because <a> doesn't even have a title attribute. <a title="more data some text" href="http://mypage.com/page.html">More</a> <a title="more data other text" href="http://mypage.com/page.html">More</a> <a title="not needed" href="http://mypage.com/page.html">Not needed</a> <a href="http://mypage.com/page.html">Not needed</a> I'm using DOMXPath. How would my query look like? $xpath = new DOMXPath($doc); $q = $xpath->query('//a');

    Read the article

  • Is there a JQuery DOM manipulator/CSS selector equivalent class in PHP?

    - by DKinzer
    I know that I can use DOMDocument and DOMXPath to manipulate XML files. But, I really love JQuery, and it would be great if there was something more like JQuery in the PHP world that I could use for sever side DOM manipulation. NOTE: I'm only interested here in how JQuery Selects and Manipulates the DOM, not all the other parts of JQuerry (I guess you can say just the Pop and the Sizzle parts).

    Read the article

  • Is there a JQuery equivalent class/library in PHP?

    - by DKinzer
    Soon I'll be working on a batch script where I will need to make some changes to some HTML files. I know that I can use DOMDocument and DOMXPath to manipulate these files. But, I really love JQuery. It would be great if there was something a lot more like JQuery in the PHP world. Does anybody know if something like that exists? Thanks! D

    Read the article

  • curl_init undefined?

    - by udaya
    Hi I am importing the contacts from gmail to my page ..... The process doesnot work due to this error 'curl_init' is not defined The suggestion i got is to 1.uncomment destination curl.dll 2.copy the following libraries to the windows/system32 dir. ssleay32.dll libeay32.dll 3.copy php_curl.dll to windows/system32 After trying all these i refreshed my xampp Even then error occurs This is my page where i am trying to import the gmail contacts ` // set URL and other appropriate options curl_setopt($ch, CURLOPT_URL, "http://www.example.com/"); curl_setopt($ch, CURLOPT_HEADER, 0); // grab URL and pass it to the browser curl_exec($ch); // close cURL resource, and free up system resources curl_close($ch); ? "HOSTED_OR_GOOGLE", "Email" = $_POST['Email'], echo "Passwd" = $_POST['Passwd'], "service" = "cp", "source" = "tutsmore/1.2" ); //Now we are going to post these datas to the clientLogin url. // Initialize the curl object with the $curl = curl_init($clientlogin_url); //Make the post true curl_setopt($curl, CURLOPT_POST, true); //Passing the above array of parameters. curl_setopt($curl, CURLOPT_POSTFIELDS, $clientlogin_post); //Set this for authentication and ssl communication. curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY); //provide false to not to check the server for the certificate. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); //Tell curl to just don't echo the data but return it to a variable. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); //The variable containing response $response = curl_exec($curl); //Check whether the user is successfully login using the preg_match and save the auth key if the user //is successfully logged in preg_match("/Auth=([a-z0-9_-]+)/i", $response, $matches); $auth = $matches[1]; // Include the Auth string in the headers $headers = array("Authorization: GoogleLogin auth=" . $auth); // Make the request to the google contacts feed with the auth key $curl = curl_init('http://www.google.com/m8/feeds/contacts/default/full?max-results=10000'); //passing the headers of auth key. curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); //Return the result in a variable curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); //the variable with the response. $feed = curl_exec($curl); //Create empty array of contacts echo "contacts".$contacts=array(); //Initialize the DOMDocument object $doc=new DOMDocument(); //Check whether the feed is empty //If not empty then load that feed. if (!empty($feed)) $doc-loadHTML($feed); //Initialize the domxpath object and provide the loaded feed $xpath=new DOMXPath($doc); //Get every entry tags from the feed. $query="//entry"; $data=$xpath-query($query); //Process each entry tag foreach ($data as $node) { //children of each entry tag. $entry_nodes=$node-childNodes; //Create a temproray array. $tempArray=array(); //Process the child node of the entry tag. foreach($entry_nodes as $child) { //get the tagname of the child node. $domNodesName=$child-nodeName; switch($domNodesName) { case 'title' : { $tempArray['fullName']=$child-nodeValue; } break; case 'email' : { if (strpos($child-getAttribute('rel'),'home')!==false) $tempArray['email_1']=$child-getAttribute('address'); elseif(strpos($child-getAttribute('rel'),'work')!=false) $tempArray['email_2']=$child-getAttribute('address'); elseif(strpos($child-getAttribute('rel'),'other')!==false) $tempArray['email_3']=$child-getAttribute('address'); } break; } } if (!empty($tempArray['email_1']))$contacts[$tempArray['email_1']]=$tempArray; if(!empty($tempArray['email_2'])) $contacts[$tempArray['email_2']]=$tempArray; if(!empty($tempArray['email_3'])) $contacts[$tempArray['email_3']]=$tempArray; } foreach($contacts as $key=$val) { //Echo the email echo $key.""; } } else { //The form ? " method="POST" Email: Password: tutsmore don't save your email and password trust us. ` code is completely provided for debugging if any optimization is needed i will try to optimize the code

    Read the article

  • Extending DOMDocument and DOMNode: problem with return object

    - by Glauber Rocha
    I'm trying to extend the DOMDocument class so as to make XPath selections easier. I wrote this piece of code: class myDOMDocument extends DOMDocument { function selectNodes($xpath){ $oxpath = new DOMXPath($this); return $oxpath->query($xpath); } function selectSingleNode($xpath){ return $this->selectNodes($xpath)->item(0); } } These methods return a DOMNodeList and a DOMNode object, respectively. What I'd like to do now is to implement similar methods to the DOMNode objects. But obviously if I write a class (myDOMNode) that extends DOMNode, I won't be able to use these two extra methods on the nodes returned by myDOMDocument because they're DOMNode (and not myDOMNode) objects. I'm rather a beginner in object programming, I've tried various ideas but they all lead to a dead-end. Any hints? Thanks a lot in advance.

    Read the article

  • how to handle DOM in PHP

    - by From.ME.to.YOU
    my PHP code $dom = new DOMDocument(); @$dom->loadHTML($file); $xpath = new DOMXPath($dom); $tags = $xpath->query('//div[@class="text"]'); foreach ($tags as $tag) { echo $tag->textContent; } what i'm trying to do here is to get the content of the div that has class 'text' but the problem when i loop and echo the results i only get the text i can't get the HTML code with images and all the HTML tags like p, br,img... etc i tried to use $tag-nodeValue; but also nothing worked out any help !!?

    Read the article

  • Can I get the matched DOM string with PHP and DOMDocument?

    - by alex
    I've got my HTML inside of $html. dom = new DOMDocument(); $dom->loadHTML($html); $xpath = new DOMXPath($dom); $tags = $xpath->query('//div[@id="header"]'); foreach($tags as $tag) { var_dump($tag->nodeValue); // the innerHTML of that element var_dump($tag); // object(DOMElement)#3 (0) { } } Is there a way to get that node, or remove it? Basically, I'm parsing an existing website and need to remove elements from it. What method do I call to do that? Thanks

    Read the article

  • How to ignore CDATA tags?

    - by Petre
    I'm trying to make an html parser, but when I load the html I get warnings like this Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: Invalid char in CDATA 0x1C in Entity, line: 1302 Here is the code I use class Parser { public $url=null; public $html=null; public $tidy=null; public $head=null; public $head_xpath=null; function __construct($url){ $this->url=$url; $this->html=file_get_contents($this->url); $this->tidy=tidy_parse_string($this->html); $this->head=new DOMDocument(); $this->head->loadHTML($this->tidy->head()); $this->head_xpath= new DOMXPath($this->head); } } $x=new Parser("http://www.guardian.co.uk/politics/2012/mar/24/vince-cable-coalition-banking-row"); I searched around and found the LIBXML_NOCDATA constant, but I don't know how to set it. So how could i completely ignore CDATA?

    Read the article

  • Improving HTML scrapper efficiency with pcntl_fork()

    - by Michael Pasqualone
    With the help from two previous questions, I now have a working HTML scrapper that feeds product information into a database. What I am now trying to do is improve efficiently by wrapping my brain around with getting my scrapper working with pcntl_fork. If I split my php5-cli script into 10 separate chunks, I improve total runtime by a large factor so I know I am not i/o or cpu bound but just limited by the linear nature of my scraping functions. Using code I've cobbled together from multiple sources, I have this working test: <?php libxml_use_internal_errors(true); ini_set('max_execution_time', 0); ini_set('max_input_time', 0); set_time_limit(0); $hrefArray = array("http://slashdot.org", "http://slashdot.org", "http://slashdot.org", "http://slashdot.org"); function doDomStuff($singleHref,$childPid) { $html = new DOMDocument(); $html->loadHtmlFile($singleHref); $xPath = new DOMXPath($html); $domQuery = '//div[@id="slogan"]/h2'; $domReturn = $xPath->query($domQuery); foreach($domReturn as $return) { $slogan = $return->nodeValue; echo "Child PID #" . $childPid . " says: " . $slogan . "\n"; } } $pids = array(); foreach ($hrefArray as $singleHref) { $pid = pcntl_fork(); if ($pid == -1) { die("Couldn't fork, error!"); } elseif ($pid > 0) { // We are the parent $pids[] = $pid; } else { // We are the child $childPid = posix_getpid(); doDomStuff($singleHref,$childPid); exit(0); } } foreach ($pids as $pid) { pcntl_waitpid($pid, $status); } // Clear the libxml buffer so it doesn't fill up libxml_clear_errors(); Which raises the following questions: 1) Given my hrefArray contains 4 urls - if the array was to contain say 1,000 product urls this code would spawn 1,000 child processes? If so, what is the best way to limit the amount of processes to say 10, and again 1,000 urls as an example split the child work load to 100 products per child (10 x 100). 2) I've learn that pcntl_fork creates a copy of the process and all variables, classes, etc. What I would like to do is replace my hrefArray variable with a DOMDocument query that builds the list of products to scrape, and then feeds them off to child processes to do the processing - so spreading the load across 10 child workers. My brain is telling I need to do something like the following (obviously this doesn't work, so don't run it): <?php libxml_use_internal_errors(true); ini_set('max_execution_time', 0); ini_set('max_input_time', 0); set_time_limit(0); $maxChildWorkers = 10; $html = new DOMDocument(); $html->loadHtmlFile('http://xxxx'); $xPath = new DOMXPath($html); $domQuery = '//div[@id=productDetail]/a'; $domReturn = $xPath->query($domQuery); $hrefsArray[] = $domReturn->getAttribute('href'); function doDomStuff($singleHref) { // Do stuff here with each product } // To figure out: Split href array into $maxChilderWorks # of workArray1, workArray2 ... workArray10. $pids = array(); foreach ($workArray(1,2,3 ... 10) as $singleHref) { $pid = pcntl_fork(); if ($pid == -1) { die("Couldn't fork, error!"); } elseif ($pid > 0) { // We are the parent $pids[] = $pid; } else { // We are the child $childPid = posix_getpid(); doDomStuff($singleHref); exit(0); } } foreach ($pids as $pid) { pcntl_waitpid($pid, $status); } // Clear the libxml buffer so it doesn't fill up libxml_clear_errors(); But what I can't figure out is how to build my hrefsArray[] in the master/parent process only and feed it off to the child process. Currently everything I've tried causes loops in the child processes. I.e. my hrefsArray gets built in the master, and in each subsequent child process. I am sure I am going about this all totally wrong, so would greatly appreciate just general nudge in the right direction.

    Read the article

  • How do I show the print with AJAX/jQuery?

    - by Doug
    So I'm trying to understand this whole AJAX/jQuery thing. Right now, when I run this PHP script alone, I would have to wait and watch the wheel spin until it's done with the loop and then it will load. while ( $row = mysql_fetch_array($res) ) { postcode_to_storm( $row['Test'] ); $dom = new DOMDocument(); @$dom->loadHTML($result); $xPath = new DOMXPath($dom); $failInvite = 'Rejected'; $findFalse = strpos($result, $failInvite); if ( $findFalse == true ) { $array[$i] = $row['Test']; $i++; echo $array[$i]}; } } Now, how do I use AJAX/jQuery to show echo $array[$i]}; everytime it is invoked instead of waiting for the whole process to complete?

    Read the article

  • How to get title from a website by xpath?

    - by qxxx
    I am playing around with xpath, but have no Idea how to for example get a title from a website using xpath, here is my code but I don't know what to do next... $dom = new DOMDocument(); $dom->loadHTMLFile("http://www.cool.de"); $x=new DOMXPath($dom); $result = $x->query("//TITLE"); //...??? and print_r($result) shows me only "Object", is there a function like print_r to see what is inside an object so I don't have to guess?

    Read the article

  • PHP XML Strategy: Parsing DOM to fill "Bean"

    - by Mike
    I have a question concerning a good strategy on how to fill a data "bean" with data inside an xml file. The bean might look like this: class Person { var $id; var $forename = ""; var $surname = ""; var $bio = new Biography(); } class Biography { var $url = ""; var $id; } the xml subtree containing the info might look like this: <root> <!-- some more parent elements before node(s) of interest --> <person> <name pre="forename"> Foo </name> <name pre="surname"> Bar </name> <id> 1254 </id> <biography> <url> http://www.someurl.com </url> <id> 5488 </id> </biography> </person> </root> At the moment, I have one approach using DOMDocument. A method iterates over the entries and fills the bean by "remembering" the last node. I think thats not a good approach. What I have in mind is something like preconstructing some xpath expression(s) and then iterate over the subtrees/nodeLists. Return an array containing the beans as defined above eventually. However, it seems not to be possible reusing a subtree /DOMNode as DOMXPath constructor parameter. Has anyone of you encountered such a problem?

    Read the article

  • How do you query namespaces with PHP/XPath/DOM

    - by Alsbury
    I am trying to query an XML document that uses namespaces. I have had success with xpath without namespaces, but no results with namespaces. This is a basic example of what I was trying. I have condensed it slightly, so there may be small issues in my sample that may detract from my actual problem. Sample XML: <?xml version="1.0"?> <sf:page> <sf:section> <sf:layout> <sf:p>My Content</sf:p> </sf:layout> </sf:section> </sf:page> Sample PHP Code: <?php $path = "index.xml"; $content = file_get_contents($path); $dom = new DOMDocument($content); $xpath = new DOMXPath($dom); $xpath->registerNamespace('sf', "http://developer.apple.com/namespaces/sf"); $p = $xpath->query("//sf:p", $dom); My result is that "p" is a "DOMNodeList Object ( )" and it's length is 0. Any help would be appreciated.

    Read the article

  • maintaining continuous count in php

    - by LiveEn
    I have a small problem maintain a count for the position. i have written a function function that will select all the users within a page and positions them in the order. Eg: Mike Position 1 Steve Postion 2.............. .... Jacob Position 30 but the problem that i have when i move to the second page, the count is started from first Eg: Jenny should be number 31 but the list goes, Jenny Position 1 Tanya Position 2....... Below is my function function nrk($duty,$page,$position) { $url="http://www.test.com/people.php?q=$duty&start=$page"; $ch=curl_init(); curl_setopt($ch,CURLOPT_URL,$url); $result=curl_exec($ch); $dom = new DOMDocument(); @$dom->loadHTML($result); $xpath=new DOMXPath($dom); $elements = $xpath->evaluate("//div"); foreach ($elements as $element) { $name = $element->getElementsByTagName("name")->item(0)->nodeValue; $position=$position+1; echo $name." Position:".$position."<br>"; } return $position; } Below is the for loop where i try to loop thru the page count for ($page=0;$page<=$pageNumb;$page=$page + 10) { nrk($duty,$page,$position); } I dont want to maintain a array key value in the for each coz i drop certain names...

    Read the article

  • PHP & cUrl - POST problems in while loop.

    - by Max Hoff
    I have a while loop, with cUrl inside. (I can't use curl_multi for various reasons.) The problem is that cUrl seems to save the data it POSTS after each loop traversal. For instance, if parameter X is One the first loop through, and if it's Two the second loop through, cUrl posts: "One,Two". It should just POST "Two".(This is despite closing and unsetting the curl handle.) Here's a simplified version of the code (with unecessary info stripped out): while(true){ // code to form the $url. this code is local to the loop. so the variables should be "erased" and made new for each loop through. $ch = curl_init(); $userAgent = 'Googlebot/2.1 (http://www.googlebot.com/bot.html)'; curl_setopt($ch,CURLOPT_USERAGENT, $userAgent); curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_POST,count($fields)); curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string); curl_setopt($ch, CURLOPT_FAILONERROR, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_AUTOREFERER, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER,true); curl_setopt($ch, CURLOPT_TIMEOUT, 10); $html = curl_exec($ch); curl_close($ch); unset($ch); $dom = new DOMDocument(); @$dom->loadHTML($html); $xpath = new DOMXPath($dom); $resultTable = $xpath->evaluate("/html/body//table"); // $resultTable is 20 the first time through the loop, and 0 everytime thereafter becauset he POSTing doesn't work right with the "saved" parameters. What am I doing wrong here?

    Read the article

  • Capturing Drupal7 DOM content before page load for comparison

    - by ehime
    We have an MU (Multisite) installation of Drupal7 here at work, and are trying to temporarily hold back the swarm of bots we receive until we get a chance to load our content. I wrote a quick and and dirty script to send 503 headers if we find a certain criteria in Xpath (This can ALSO be done as a strpos/preg_match if DOM is not formed). In order to get the ball rolling though I need to figure out how to either A) Hijack the Drupal7 bootstrap and pull all content through this filter below B) ob_flush content through the filter before content is loaded The issue that I am having is figuring out exactly where I can catch the content at? I thought that index.php in Drupal7 would be the suspect, but I'm a little confused as to where or how I should capture the contents. Here's the script, and hopefully someone can point me in the right direction. //error_reporting(-1); /* start query */ $dom = new DOMDocument; $dom->preserveWhiteSpace = false; $dom->Load($_SERVER['PHP_SELF']); $xpath = new DOMXPath($dom); //if this exists we aren't ready to be read by bots $query = $xpath->query(".//*[@id='block-views-about-this-site-block']/div/div/div"); //or $query = 'klat-badge'; //if this is a string not DOM /* end query */ if(strpos($query) !== false) { //require banlist require('botlist.php'); $str = strtolower('/'.implode('|', array_unique($list)).'/i'); if(preg_match($str, strtolower($_SERVER['HTTP_USER_AGENT']))) { //so tell bots we're broken header('HTTP/1.1 503 Service Temporarily Unavailable'); header('Status: 503 Service Temporarily Unavailable'); exit; } }

    Read the article

  • PHP XML Parsing

    - by ashchawla
    Hi I am making get request in PHP but the parser is having issues. I am looking for a way to retreive the value of URL in the following example. The response xml looks like this. <?xml version="1.0" encoding="iso-8859-1" standalone="no"?> <testtemplate JobName="test1"> <Sources> <Source xmlns="http://www.microsoft.com/test/schema/api"> <System> <SystemIdentifier>HTTPS</SystemIdentifier> <URL>http://example.com</URL> </System> </Source> </Sources> <testtemplate> and my PHP code looks like this: $xml = DOMDocument::LoadXML($response); $mypath = new DOMXPath($xml); $mypath->registerNamespace("a", "http://www.microsoft.com/test/schema/api"); $url = $mypath->evaluate("/testtemplate/Sources/Source/System/URL"); $message = $url->item(0)->value; print($message); Any help would be appreciated. Thanks Ashish

    Read the article

  • Failed to load url in Dom Document?

    - by Lakhan
    im trying to get latitude and longtitude from google map by giving address. But its giving error.when i directly copy url to browser url bar.its giving correct result.If anybody know the answer .Plz reply. Thanx in advance Here is my code. <?php $key = '[AIzaSyAoPgQlfKsBKQcBGB01cl8KmiPee3SmpU0]'; $opt = array ( 'address' => urlencode('Kolkata,India, ON') , 'output' => 'xml' ); $url = 'http://maps.google.com/maps/geo?q='.$opt['address'].'&output='.$opt['output'].'&oe=utf8&key='.$key; $dom = new DOMDocument(); $dom->load($url); $xpath = new DomXPath($dom); $xpath->registerNamespace('ge', 'http://earth.google.com/kml/2.0'); $statusCode = $xpath->query('//ge:Status/ge:code'); if ($statusCode->item(0)->nodeValue == '200') { $pointStr = $xpath->query('//ge:coordinates'); $point = explode(",", $pointStr->item(0)->nodeValue); $lat = $point[1]; $lon = $point[0]; echo '<pre>'; echo 'Lat: '.$lat.', Lon: '.$lon; echo '</pre>'; } ?> Following error has occured: Warning: DOMDocument::load(http://maps.google.com/maps/geo? q=Kolkata%252CIndia%252C%2BON&output=xml&oe=utf8&key=%5BAIzaSyAoPgQlfKsBKQcBGB01cl8KmiPee3SmpU0%5D) [domdocument.load]: failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request in C:\xampp\htdocs\draw\draw.php on line 19 Warning: DOMDocument::load() [domdocument.load]: I/O warning : failed to load external entity "http://maps.google.com/maps/geo?q=Kolkata%252CIndia%252C%2BON&output=xml&oe=utf8&key=%5BAIzaSyAoPgQlfKsBKQcBGB01cl8KmiPee3SmpU0%5D" in C:\xampp\htdocs\draw\draw.php on line 19 Notice: Trying to get property of non-object in C:\xampp\htdocs\draw\draw.php on line 26

    Read the article

  • problem calculating the position using php

    - by LiveEn
    I have a function below which gets name from a site. Below is the partial code, not complete. The values are passed thru a for loop using php. function funct($$name,$page) { $url="http://testserver.com/client?list=$name&page=$page"; $ch=curl_init(); curl_setopt($ch,CURLOPT_URL,url); $result=curl_exec($ch); $dom = new DOMDocument(); @$dom->loadHTML($result); $xpath=new DOMXPath($dom); $elements = $xpath->evaluate("//div"); foreach ($elements as $element) { $name = $element->getElementsByTagName("name")->item(0)->nodeValue; $position=$position +1; echo $name.$position; } } The code works fine but when i get a name i need to add a position and for each name it will be incremented by 1 to make it contentious. But when the values for the pages are passed, for an example when i move from page 1 to page 2. the count starts again from first, next page... same problem. How can i make it continues on every page?

    Read the article

1 2  | Next Page >