How to use Zend Dom Query without Zend FW?

Can I use Zend Dom Query without the Zend Framework?

If yes: Where to download Zend Dom Query and how to use it without Zend Framework?

+4
source share
5 answers

You can extract individual ZF files using some package managers, such as this one , which will tell you what files you need and compress them for you. Zend_Dom_Query only requires

  • Zend / Home / Query.php
  • Zend / Home / Query / Css2Xpath.php
  • Zend / Home / Query / Result.php
  • Zend / Home / Exception.php
  • Zend / Exception.php

In any case, it is available for download . If there is an urgent need - there are many other tools like this, not just for ZF.

+6
source

Classes in Zend are not intended for stand-alone use - is there a reason why you cannot use all of ZF, but only use Zend_Dom_Query?

Otherwise, you can get the folder

/ Library / Home /

And pull it out of the ZF folder, you will need to look for any dependencies, and you will need a quick look:

/library/Exception/Exception.php

Give it back, let us know how it goes.

+1
source

I assume that “without the Zend Framework” you mean without using the components of the Zend Framework MVC. You can use any component of the Zend Framework individually; this is the glue base.

Download the library and extract it to the project library folder or include the PHP path. It should be about as simple as:

<?php require_once 'Zend/Dom/Query.php'; $query = new Zend_Dom_Query(....); 
+1
source

It seems to me that this approach does not work with Zend Framework 2, I do not know why ...

+1
source

You can use zendframework/zend-dom as a standalone component. It has no external dependencies, which means that it does not need another Zend component or another library.

Alternatively, you can also use a library completely unrelated to Zend, like tburry/pquery or my PHPPowertools/DOM-Query . Both libraries perform the same functions as zendframework/zend-dom , but the syntax is different and HTML5 support may vary for each library.

Example:

This example shows how you load an HTML string and a query for .foo .bar a from each of these three libraries:

Using zendframework/zend-dom , you will do the following:

 use \Zend\Dom\Query; $dom = new Query($htmlcode); $results = $dom->execute('.foo .bar a'); 

Using tburry/pquery you will do the following:

 use \pQuery\pQuery $dom = pQuery::parseStr($htmlcode); $dom->query('.foo .bar a'); 

Using PHPPowertools/DOM-Query , you will do the following:

 use \PowerTools\DOM_Query $H = new DOM_Query($htmlcode); $s = $H->select('.foo .bar a'); 

Choose your poison!

0
source

Source: https://habr.com/ru/post/1340697/


All Articles