Skip to content

Tag: dom

Add domain to src attribute value if a relative path

I have a text variable which contains multiple images with a relative or absolute path. I need to check if the src attribute starts with http or https then ignore it, but in case it starts with / or something like abc/ then prepend a base url. I tried like below: My output is: Issue here: I got 99% result

Remove Child does not contain attribute value

I am practicing with XML DOM PHP parsing. I have such XML file (shorter version): I created attribute with name “id” and value “2” for two Tag elements. Now I would like to: Get only Tag elements which did not contain attribute ‘id=”2″‘; Get only Tag elements wh…

replace li tag with different tag according to the bullet level

need to replace the li tags with different customized tag according to the bullet level, For the li level1 keep it as is, for level2 change li to lii, for level3 change li to liii For example for the input below (I have only 2 bullet levels in the below code just as example) desired output as you can see

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?