# PHP Patch for loadHTML options

- Thread: https://externals.io/message/51452
- Original archive: https://news-web.php.net/php.internals/51452
- Started by James Devine on 2011-02-16T23:57:03+00:00
- Messages: 5
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #51452 — James Devine — 2011-02-16T23:57:03+00:00

URL: https://externals.io/message/51452#51452

I've included a patch for review adding the ability to optionally pass
options to the DOMDocument::loadHTML[File] functions


diff -ru php-5.3.5.orig/ext/dom/document.c php-5.3.5.new/ext/dom/document.c
--- php-5.3.5.orig/ext/dom/document.c   2010-04-02 14:08:15.000000000 -0600
+++ php-5.3.5.new/ext/dom/document.c    2011-02-16 16:49:20.000000000 -0700
@@ -149,10 +149,12 @@

 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_loadhtml, 0, 0, 1)
        ZEND_ARG_INFO(0, source)
+       ZEND_ARG_INFO(0, options)
 ZEND_END_ARG_INFO();

 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_loadhtmlfile, 0, 0, 1)
        ZEND_ARG_INFO(0, source)
+       ZEND_ARG_INFO(0, options)
 ZEND_END_ARG_INFO();

 ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_savehtml, 0, 0, 0)
@@ -2157,10 +2159,11 @@
        char *source;
        int source_len, refcount, ret;
        htmlParserCtxtPtr ctxt;
+       int options = 0;

        id = getThis();

-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s",
&source, &source_len) == FAILURE) {
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l",
&source, &source_len, &options) == FAILURE) {
                return;
        }

@@ -2180,6 +2183,9 @@
                RETURN_FALSE;
        }

+       if(options)
+               htmlCtxtUseOptions(ctxt, options);
+
        ctxt->vctxt.error = php_libxml_ctx_error;
        ctxt->vctxt.warning = php_libxml_ctx_warning;
        if (ctxt->sax != NULL) {

---

## #51454 — Pierre Joye — 2011-02-17T13:43:23+00:00

URL: https://externals.io/message/51452#51454 · In reply to: #51452

hi,

Can you make a patch against trunk instead please?

Also pls follow the CS:

if (foo) {
}

Ideally attach your patch to a feature request at bugs.php.net, so we
won't loose it :)

thanks for your work!

Cheers,


> I've included a patch for review adding the ability to optionally pass
> options to the DOMDocument::loadHTML[File] functions
>
>
> diff -ru php-5.3.5.orig/ext/dom/document.c php-5.3.5.new/ext/dom/document.c
> --- php-5.3.5.orig/ext/dom/document.c   2010-04-02 14:08:15.000000000 -0600
> +++ php-5.3.5.new/ext/dom/document.c    2011-02-16 16:49:20.000000000 -0700
> @@ -149,10 +149,12 @@
>
>  ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_loadhtml, 0, 0, 1)
>        ZEND_ARG_INFO(0, source)
> +       ZEND_ARG_INFO(0, options)
>  ZEND_END_ARG_INFO();
>
>  ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_loadhtmlfile, 0, 0, 1)
>        ZEND_ARG_INFO(0, source)
> +       ZEND_ARG_INFO(0, options)
>  ZEND_END_ARG_INFO();
>
>  ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_document_savehtml, 0, 0, 0)
> @@ -2157,10 +2159,11 @@
>        char *source;
>        int source_len, refcount, ret;
>        htmlParserCtxtPtr ctxt;
> +       int options = 0;
>
>        id = getThis();
>
> -       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s",
> &source, &source_len) == FAILURE) {
> +       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l",
> &source, &source_len, &options) == FAILURE) {
>                return;
>        }
>
> @@ -2180,6 +2183,9 @@
>                RETURN_FALSE;
>        }
>
> +       if(options)
> +               htmlCtxtUseOptions(ctxt, options);
> +
>        ctxt->vctxt.error = php_libxml_ctx_error;
>        ctxt->vctxt.warning = php_libxml_ctx_warning;
>        if (ctxt->sax != NULL) {
>
> --
> 
> 
>
>



-- 
Pierre

@pierrejoye | http://blog.thepimp.net | http://www.libgd.org

---

## #51456 — James Devine — 2011-02-17T15:29:38+00:00

URL: https://externals.io/message/51452#51456 · In reply to: #51454

Will do, thanks!


> hi,
>
> Can you make a patch against trunk instead please?
>
> Also pls follow the CS:
>
> if (foo) {
> }
>
> Ideally attach your patch to a feature request at bugs.php.net, so we
> won't loose it :)
>
> thanks for your work!
>
> Cheers,
>
> 
> > […]
>
>
>
> --
> Pierre
>
> @pierrejoye | http://blog.thepimp.net | http://www.libgd.org

---

## #51460 — Christian Stocker — 2011-02-17T19:52:40+00:00

URL: https://externals.io/message/51452#51460 · In reply to: #51456

Hi

Looks good to me. But can you add the constants from:
typedef enum {
    HTML_PARSE_RECOVER  = 1<<0, /* Relaxed parsing */
    HTML_PARSE_NODEFDTD = 1<<2, /* do not default a doctype if not found */
    HTML_PARSE_NOERROR	= 1<<5,	/* suppress error reports */
    HTML_PARSE_NOWARNING= 1<<6,	/* suppress warning reports */
    HTML_PARSE_PEDANTIC	= 1<<7,	/* pedantic error reporting */
    HTML_PARSE_NOBLANKS	= 1<<8,	/* remove blank nodes */
    HTML_PARSE_NONET	= 1<<11,/* Forbid network access */
    HTML_PARSE_NOIMPLIED= 1<<13,/* Do not add implied html/body...
elements */
    HTML_PARSE_COMPACT  = 1<<16 /* compact small text nodes */
} htmlParserOption;

also to it, so that they are available from PHP? I don't like guessing
integers :)

Maybe we don't have to extra define the ones already defined in
xmlParserOption , eg XML_PARSE_NOERROR, but there's no compagnion to
HTML_PARSE_NODEFDTD and HTML_PARSE_NOIMPLIED

chregu


> Will do, thanks!
> 
> 
> > […]

---

## #51464 — James Devine — 2011-02-17T23:26:53+00:00

URL: https://externals.io/message/51452#51464 · In reply to: #51460

I've updated bug request #54037 to include a patch which creates HTML
specific constants for HTML_PARSE_NODEFDTD and HTML_PARSE_NOIMPLIED,
it also creates `LIBXML_PEDANTIC` and `LIBXML_RECOVER` constants

On Thu, Feb 17, 2011 at 12:52 PM, Christian Stocker
<christian.stocker@liip.ch> wrote:
> Hi
>
> Looks good to me. But can you add the constants from:
> typedef enum {
>    HTML_PARSE_RECOVER  = 1<<0, /* Relaxed parsing */
>    HTML_PARSE_NODEFDTD = 1<<2, /* do not default a doctype if not found */
>    HTML_PARSE_NOERROR  = 1<<5, /* suppress error reports */
>    HTML_PARSE_NOWARNING= 1<<6, /* suppress warning reports */
>    HTML_PARSE_PEDANTIC = 1<<7, /* pedantic error reporting */
>    HTML_PARSE_NOBLANKS = 1<<8, /* remove blank nodes */
>    HTML_PARSE_NONET    = 1<<11,/* Forbid network access */
>    HTML_PARSE_NOIMPLIED= 1<<13,/* Do not add implied html/body...
> elements */
>    HTML_PARSE_COMPACT  = 1<<16 /* compact small text nodes */
> } htmlParserOption;
>
> also to it, so that they are available from PHP? I don't like guessing
> integers :)
>
> Maybe we don't have to extra define the ones already defined in
> xmlParserOption , eg XML_PARSE_NOERROR, but there's no compagnion to
> HTML_PARSE_NODEFDTD and HTML_PARSE_NOIMPLIED
>
> chregu
>
> 
> > […]
