PHP code example of phptek / phpquery
1. Go to this page and download the library: Download phptek/phpquery library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
phptek / phpquery example snippets
e = 'test.html'; // see below for source
// loads the file
// basically think of your php script as a regular HTML page running client side with jQuery. This loads whatever file you want to be the current page
phpQuery::newDocumentFileHTML($file);
// Once the page is loaded, you can then make queries on whatever DOM is loaded.
// This example grabs the title of the currently loaded page.
$titleElement = pq('title'); // in jQuery, this would return a jQuery object. I'm guessing something similar is happening here with pq.
// You can then use any of the functionality available to that pq object. Such as getting the innerHTML like I do here.
$title = $titleElement->html();
// And output the result
echo '<h2>Title:</h2>';
echo '<p>' . htmlentities( $title) . '</p>';