PHP code example of gravitypdf / querypath

1. Go to this page and download the library: Download gravitypdf/querypath 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/ */

    

gravitypdf / querypath example snippets



// Assuming you installed from Composer:
tml5 library to process the HTML
	$qp = html5qp(__DIR__.'/path/to/file.html'); // load a file from disk
	$qp = html5qp('<div>You can pass a string of HTML directly to the function</div>'); // load a string
} catch (\QueryPath\Exception $e) {
	// Handle error
}

try {
	// Legacy: uses libxml to parse HTML
	$qp = htmlqp(__DIR__.'/path/to/file.html'); // load a file from disk
	$qp = htmlqp('<div>You can pass a string of HTML directly to the function</div>'); // load a string
} catch (\QueryPath\Exception $e) {
	// Handle error
}

try {
	// XML or XHTML
	$qp = qp(__DIR__.'/path/to/file.html'); // load a file from disk
	$qp = qp("<?xml version='1.0'

try {
	html5qp(\QueryPath\QueryPath::HTML5_STUB, 'title')
		// Add some text to the title
		->text('Example of QueryPath.')
		// Now look for the <body> element
		->top('body')
		// Inside the body, add a title and paragraph.
		->append('<h1>This is a test page</h1><p>Test text</p>')
		// Now we select the paragraph we just created inside the body
		->children('p')
		// Add a 'class="some-class"' attribute to the paragraph
		->attr('class', 'some-class')
		// And add a style attribute, too, setting the background color.
		->css('background-color', '#eee')
		// Now go back to the paragraph again
		->parent()
		// Before the paragraph and the title, add an empty table.
		->prepend('<table id="my-table"></table>')
		// Now let's go to the table...
		->top('#my-table')
		// Add a couple of empty rows
		->append('<tr></tr><tr></tr>')
		// select the rows (both at once)
		->children()
		// Add a CSS class to both rows
		->addClass('table-row')
		// Now just get the first row (at position 0)
		->eq(0)
		// Add a table header in the first row
		->append('<th>This is the header</th>')
		// Now go to the next row
		->next()
		// Add some data to this row
		->append('<td>This is the data</td>')
		// Write it all out as HTML
		->writeHTML5();
} catch (\QueryPath\Exception $e) {
	// Handle error
}

try {
	$html = '
    <ul>
        <li>Foo</li>
        <li>Bar</li>
        <li>FooBar</li>
    </ul>';

	$qp = html5qp($html);
	foreach ($qp->find('li') as $li) {
		echo $li->text() .'<br>';
	}
} catch (\QueryPath\Exception $e) {
	// Handle error
}