GravityPDF / querypath

A fork of QueryPath: a PHP library for HTML(5)/XML querying (CSS 4 or XPath) and processing (like jQuery) with PHP8.3 support
Other
21 stars 2 forks source link

How to create HTML tags? #11

Closed jakejackson1 closed 1 year ago

jakejackson1 commented 1 year ago

From querypath created by salarmehr: technosophos/querypath#178

Running

echo qp('<div>s</div>')->html();

similar to other jQuery PHP implementation, I expect to get <div>s</div> but it returns a complete document:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><body><div>s</div></body></html>

and I have to use qp('<div>s</div>')->top('body *')->html(); which is cumbersome. In particular when use what to build several section of a page programmatically and merge them

jakejackson1 commented 1 year ago

echo qp('<div></div>')->innerHtml(); reutrns <body> <div/></body>

It seems there is no difference between the output of html5() and html()

jakejackson1 commented 1 year ago

Does innerHtml() work?

You may also consider switching the parser to the HTML5 one. It's less picky than the built-in libxml html 4 parser. I can't remember if it will make a difference, but you can try html5() instead of html and see if that helps.