domdocument

Problems Indenting HTML(5) with PHP

这一生的挚爱 提交于 2021-02-19 05:52:47
问题 Disclaimer: Please bare with the length of this question. This is a recurring question for a real world problem that I've seen asked hundreds of times with no clear, working solution ever being presented. I have hundreds of HTML files I want to mass indent using PHP. At first I thought of using Tidy but as you should know, it's not compatible by default with HTML5 tags and attributes, after some research and even more tests I came up with the following implementation that "fakes" HTML 5

Avoid percent-encoding href attributes when using PHP's DOMDocument

走远了吗. 提交于 2021-02-18 11:11:29
问题 The best answers I was able to find for this issue are using XSLT, but I'm just not sure how to apply those answers to my problem. Basically, DOMDocument is doing a fine job of escaping URLs (in href attributes) that are passed in, but I'm actually using it to build a Twig/Django style template, and I'd rather it leave them alone. Here's a specific example, illustrating the "problem": <?php $doc = new DOMDocument(); $doc->loadHTML('<html><body>Test<br><a href="{{variable}}"></a></body></html>

How to replace img src and link href in a document with a mustache expression?

跟風遠走 提交于 2021-02-11 16:31:17
问题 I trying to replace the src , href value but with a small modified using regex Simple example //Find: <img src="icons/google-icon.svg" > //Replace to: <img src="{{asset('icons/google-icon.svg')}}" > //Find: <link href="css/style.css"> //Replace to: <link href="{{asset('css/style.css')}}"> /** etc... */ Now this is my regex: //Find: src\s*=\s*"(.+?)" //Replace to: src="{{ asset('$1') }}" And its work very great actually but its only for src not [ href , src ], also I want to exclude any value

How to replace img src and link href in a document with a mustache expression?

让人想犯罪 __ 提交于 2021-02-11 16:29:29
问题 I trying to replace the src , href value but with a small modified using regex Simple example //Find: <img src="icons/google-icon.svg" > //Replace to: <img src="{{asset('icons/google-icon.svg')}}" > //Find: <link href="css/style.css"> //Replace to: <link href="{{asset('css/style.css')}}"> /** etc... */ Now this is my regex: //Find: src\s*=\s*"(.+?)" //Replace to: src="{{ asset('$1') }}" And its work very great actually but its only for src not [ href , src ], also I want to exclude any value

Nodes in XML does not appear to be identified/utilizable

前提是你 提交于 2021-02-11 15:01:20
问题 I am probably making some kind of stupid mistake here, but I'm stuck, so hopefully some of you can help me out. I Have loaded an XML to xmlDoc through post, using DOMDocument and XMLHTTP Set xmlhtp = CreateObject("MSXML2.XMLHTTP.6.0") Set xmlDoc = CreateObject("MSXML2.DOMDocument.6.0") When I recieve the response from the API I write it to a cell to check the response, and it loads there. I find my Nodes and my information. I write it to a cell with With xmlhtp .Open "post", sURL, False

Split all html tags into a array

回眸只為那壹抹淺笑 提交于 2021-02-08 12:09:17
问题 Let's suppose that I have this code below: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Title of the document</title> </head> <body> <div id="x">Hello</div> <p>world</p> <h1>my name</h1> </body> </html> And I need to extract all html tags and put inside a array, like this: '0' => '<!DOCTYPE html>', '1' => '<html>', '2' => '<head>', '3' => '<meta charset="UTF-8">', '4' => '<title>Title of the document</title>', '5' => '</head>', '6' => '<body>', '7' => '<div id="x">Hello</div>',

Split all html tags into a array

送分小仙女□ 提交于 2021-02-08 12:06:44
问题 Let's suppose that I have this code below: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Title of the document</title> </head> <body> <div id="x">Hello</div> <p>world</p> <h1>my name</h1> </body> </html> And I need to extract all html tags and put inside a array, like this: '0' => '<!DOCTYPE html>', '1' => '<html>', '2' => '<head>', '3' => '<meta charset="UTF-8">', '4' => '<title>Title of the document</title>', '5' => '</head>', '6' => '<body>', '7' => '<div id="x">Hello</div>',

How to parse a OFX (Version 1.0.2) file in PHP?

流过昼夜 提交于 2021-02-07 12:26:22
问题 I have a OFX file downloaded from Citibank, this file has a DTD defined at http://www.ofx.net/DownloadPage/Files/ofx102spec.zip (file OFXBANK.DTD), the OFX file appear to be SGML valid. I'm trying with DomDocument of PHP 5.4.13, but I get several warning and file is not parsed. My Code is: $file = "source/ACCT_013.OFX"; $dtd = "source/ofx102spec/OFXBANK.DTD"; $doc = new DomDocument(); $doc->loadHTMLFile($file); $doc->schemaValidate($dtd); $dom->validateOnParse = true; The OFX file start as:

PHP DOMDocument: Errors while parsing unescaped strings

十年热恋 提交于 2021-02-07 05:15:03
问题 I'm having an issue while parsing HTML with PHP's DOMDocument . The HMTL i'm parsing has the following script tag : <script type="text/javascript"> var showShareBarUI_params_e81 = { buttonWithCountTemplate: '<div class="sBtnWrap"><a href="#" onclick="$onClick"><div class="sBtn">$text<img src="$iconImg" /></div><div class="sCountBox">$count</div></a></div>', } </script> This snippet has two problems: 1) The HTML inside the buttonWithCountTemplate var is not escaped. DOMDocument manages this

PHP DOMDocument: Errors while parsing unescaped strings

蹲街弑〆低调 提交于 2021-02-07 05:13:51
问题 I'm having an issue while parsing HTML with PHP's DOMDocument . The HMTL i'm parsing has the following script tag : <script type="text/javascript"> var showShareBarUI_params_e81 = { buttonWithCountTemplate: '<div class="sBtnWrap"><a href="#" onclick="$onClick"><div class="sBtn">$text<img src="$iconImg" /></div><div class="sCountBox">$count</div></a></div>', } </script> This snippet has two problems: 1) The HTML inside the buttonWithCountTemplate var is not escaped. DOMDocument manages this