Skip to content
Advertisement

Tag: xpath

PHP xPath with multiple not conditions

I want to select all the images but exclude the images under id=”adminbar” and the images start with or contain src=”data:image i tried this but it just excludes the images under id=”adminbar” //img[not(ancestor::div[@id=”wpadminbar”])] how to add not again to exclude all the img contain or startwith src=”data:image Answer You can just add another predicate to the end of the expression,

How to search in XML? (PHP)

I am working on a word application. I’m trying to get values from XML. My goal is getting the first and last letter of a word. Could you help me, please? PHP code: Answer The letter is in an attribute named ‘category’. Or in SimpleXML

Extract content with Xpath and data attribute

I need to extract the content of the following div tag which has the data-visible=”1″ attribute and contains the div id “line”. I tried it like that, but I dont get any result. What is the right way to extract the content with these both conditions and get the result: Answer Since this is a single element you should not

PHP / Xpath – if / else to check external site div content

I am using XPATH and PHP to retrieve operational status content of an external website div How can I test if the text within the target div ‘status’ is “All Systems Operational” example (I know it’s not correct!) Answer Use this XPath to test it already using XPath:

How to compare conetent with two tags using Xpath

I have below scenarios of $html contents. I want to check if html content is start with a media (image or video, iframe) without any text content like 3rd scenario. //no contetn between first p tag and image tag //no content between first p tag and video tag //having content inside first p tag I have tried like this but

Why using DOMDocument makes site load slower?

I’m using DOMDocument with xpath to load some data to my site from external (fast) website. Right now I use 4 urls (please see below). I need to increase to 8 urls. What I have noticed, that the more of those you add, the more slower the site loads. Is there any way to use xpath for more faster load?

PHP iterate every node of html string including text nodes splited by other nodes

I trying to change every readable part of given HTML code using DOMDocument and DOMXPath It gives me But strings “TEST_1” and “TEST_2” not changed, because of $xpath->evaluate(‘//[count() = 0]’) gives me only nodes without childrens. How to get all nodes with nodes like “TEST_1” and “TEST_2”? How to prevent adding <html> and <body> tags to result? Answer Unfortunately, I

PHP simpleXMLelment xpath returns unexpected results

I have executed the following code on the the sample XML at the bottom of the question and I am getting unexpected results. I would expect this to return only the two record nodes that are children of the current addresses node. But, it actually returns all 5 of the record nodes of the original $xml element. Everything I have

Return array of all div class names from html source using php

from a html source, using dom and xpath how would I return an array containing all the div class names? I use the following which returns all the div class names that contain “XX”, but don’t know the query to use for $targets to return all. I know this should be simple but I can’t find one that works. Thanks.

Advertisement