Skip to content

Tag: domdocument

php DOMDocument preg_replace fail detect

Basically, I want to replace content with hyperlink when detected matching keyword tag. the replace need to be outside of caption/image/figure/figcaption/iframe/a of existing content, because putting hyperlink inside these will causing format breaking. my php Now I facing 2 issue want to exclude replace hyperlink tag into but it fail on regex.. currently it display like this… this DOMDocument loadHTML

Creating DOMDocument in PHP

When I execute this code multiple times, something like this happens: but I want the divs in a row like this: for some reasons it is working with <button>. Answer Your code needs some modification: It’s better to create $dom and echo results outside the while loop. Because in your example you need just one DOM object. When trying to

PHP Split XML based on multiple nodes

I honestly tried to find a solution for php, but a lot of threads sound similar, but are not applicable for me or are for completely different languages. I want to split an xml file based on nodes. Ideally multiple nodes, but of course one is enough and could be applied multiple times. e.g. I want to split this by

PHP DOMDocument error Entity ‘nbsp’ not defined

I use DOMDocument for editing some HTML files, but some of theme have in their names spaces. So DOMDocument automaticly change the spaces to %20 and then can’t find them. This is how looks the error exactly: How to repair this error? Answer Use DOMDocument::loadHTMLFile() instead of load(). That’s what it has been made for. HTML is not XML. XML

PHP XML how to output nice format

Here are the codes: If I print it in the browser I don’t get nice XML structure like I just get And I want to be utf-8 How is this all possible to do? Answer You can try to do this: You can make set these parameter right after you’ve created the DOMDocument as well: That’s probably more concise. Output

Is there a way to get all of a DOMElement’s attributes?

I’m reading some XML with PHP and currently using the DOMDocument class to do so. I need a way to grab the names and values of a tag’s (instance of DOMElement) attributes, without knowing beforehand what any of them are. The documentation doesn’t seem to offer anything like this. I know that I can get an attribute’s value if I