Пример #1
0
<?php

/**
 * Should output the most viewed video of the day on Youtube
 *
 * Demonstrates selectors
 *
 * @author RESS.IO Team
 * @package Pharse
 * @link https://github.com/ressio/pharse
 *
 * FORKED FROM
 * @author Niels A.D.
 * @package Ganon
 * @link http://code.google.com/p/ganon/
 *
 * @license http://dev.perl.org/licenses/artistic.html Artistic License
 */
include_once '../pharse.php';
/** @var HTML_Node $html */
$html = Pharse::file_get_dom('http://www.youtube.com/videos');
if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
    //PHP 5.3.0 and higher
    echo $html('a[href ^= "/watch"]:has(img)', 0)->toString();
} else {
    echo $html->select('a[href ^= "/watch"]:has(img)', 0)->toString();
}
Пример #2
0
 * Demonstrates advanced selectors
 *
 * @author RESS.IO Team
 * @package Pharse
 * @link https://github.com/ressio/pharse
 *
 * FORKED FROM
 * @author Niels A.D.
 * @package Ganon
 * @link http://code.google.com/p/ganon/
 *
 * @license http://dev.perl.org/licenses/artistic.html Artistic License
 */
include_once '../pharse.php';
/** @var HTML_Node $html */
$html = Pharse::file_get_dom('http://www.cnn.com/');
if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
    //PHP 5.3.0 and higher
    foreach ($html('div:has(h4) (li, h4)') as $element) {
        if ($element->tag === 'h4') {
            echo '<b>', $element->getPlainText(), '</b>';
        } else {
            echo $element->getPlainText();
        }
        echo "<br>\n";
    }
} else {
    foreach ($html->select('div:has(h4) (li, h4)') as $element) {
        if ($element->tag === 'h4') {
            echo '<b>', $element->getPlainText(), '</b>';
        } else {
Пример #3
0
  -  FORKED FROM
  -  @author Niels A.D.
  -  @package Ganon
  -  @link http://code.google.com/p/ganon/
  -
  -  @license http://dev.perl.org/licenses/artistic.html Artistic License
  -->
<html>

<h1>Minified HTML:</h1>

<?php 
include_once '../pharse.php';
//Only keep everything between body tags, delete the rest.
/** @var HTML_Node $html */
$html = Pharse::file_get_dom('http://m.nos.nl');
$html->select('"!DOCTYPE"', 0)->delete();
$html->select('head', 0)->delete();
$html->select('body', 0)->detach(true);
$html->select('html', 0)->detach(true);
//Minified version
HTML_Formatter::minify_html($html);
echo "{$html}\n";
?>

<h1>Formatted HTML:</h1>

<?php 
//Formatted version
$formatter = new HTML_Formatter(array('sort_attributes' => false, 'attributes_case' => CASE_UPPER));
$formatter->format($html);
Пример #4
0
 * Demonstrates selectors
 *
 * @author RESS.IO Team
 * @package Pharse
 * @link https://github.com/ressio/pharse
 *
 * FORKED FROM
 * @author Niels A.D.
 * @package Ganon
 * @link http://code.google.com/p/ganon/
 *
 * @license http://dev.perl.org/licenses/artistic.html Artistic License
 */
include_once '../pharse.php';
/** @var HTML_Node $html */
$html = Pharse::file_get_dom('http://newsrss.bbc.co.uk/rss/newsonline_world_edition/front_page/rss.xml');
if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
    //PHP 5.3.0 and higher
    echo 'Last updated: ', $html('lastBuildDate', 0)->getPlainText(), "<br><br>\n";
    foreach ($html('item') as $item) {
        echo 'Title: ', $item('title', 0)->getPlainText(), "<br>\n";
        echo 'Date: ', $item('pubDate', 0)->getPlainText(), "<br>\n";
        echo 'Link: ', $item('link', 0)->getPlainText(), "<br><br>\n";
    }
} else {
    echo 'Last updated: ', $html->select('lastBuildDate', 0)->getPlainText(), "<br><br>\n";
    foreach ($html->select('item') as $item) {
        echo 'Title: ', $item->select('title', 0)->getPlainText(), "<br>\n";
        echo 'Date: ', $item->select('pubDate', 0)->getPlainText(), "<br>\n";
        echo 'Link: ', $item->select('link', 0)->getPlainText(), "<br><br>\n";
    }
Пример #5
0
 * Demonstrates (advanced) selectors and nested queries
 *
 * @author RESS.IO Team
 * @package Pharse
 * @link https://github.com/ressio/pharse
 *
 * FORKED FROM
 * @author Niels A.D.
 * @package Ganon
 * @link http://code.google.com/p/ganon/
 *
 * @license http://dev.perl.org/licenses/artistic.html Artistic License
 */
include_once '../pharse.php';
/** @var HTML_Node $html */
$html = Pharse::file_get_dom('http://code.google.com/p/ganon/w/list');
if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
    //PHP 5.3.0 and higher
    foreach ($html('#resultstable tr[! id=headingrow]') as $row) {
        foreach ($row('td[class ^= "vt "]') as $col) {
            echo $col->getPlainText(), ' [', $col, "] <br>\n";
        }
        echo "<br>\n";
    }
} else {
    foreach ($html->select('#resultstable tr[! id=headingrow]') as $row) {
        foreach ($row->select('td[class ^= "vt "]') as $col) {
            echo $col->getPlainText(), ' [', $col, "] <br>\n";
        }
        echo "<br>\n";
    }
Пример #6
0
/**
 * Should output a string with parsed unicode characters
 *
 * Demonstrates UTF8
 *
 * @author RESS.IO Team
 * @package Pharse
 * @link https://github.com/ressio/pharse
 *
 * FORKED FROM
 * @author Niels A.D.
 * @package Ganon
 * @link http://code.google.com/p/ganon/
 *
 * @license http://dev.perl.org/licenses/artistic.html Artistic License
 */
include_once '../pharse.php';
header('Content-Type: text/html; charset=UTF-8');
//Make sure the header is set for UTF8 output
/** @var HTML_Node $html */
$html = Pharse::file_get_dom('_html5_utf.html');
if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
    //PHP 5.3.0 and higher
    foreach ($html('(title, h1)') as $element) {
        echo $element->getPlainText(), "<br>\n";
    }
} else {
    foreach ($html->select('(title, h1)') as $element) {
        echo $element->getPlainText(), "<br>\n";
    }
}
Пример #7
0
<?php

/**
 * Should output all sections from the SRL forums (http://villavu.com/forum/)
 *
 * Demonstrates selectors
 *
 * @author RESS.IO Team
 * @package Pharse
 * @link https://github.com/ressio/pharse
 *
 * FORKED FROM
 * @author Niels A.D.
 * @package Ganon
 * @link http://code.google.com/p/ganon/
 *
 * @license http://dev.perl.org/licenses/artistic.html Artistic License
 */
include_once '../pharse.php';
/** @var HTML_Node $html */
$html = Pharse::file_get_dom('http://villavu.com/forum/');
if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
    //PHP 5.3.0 and higher
    foreach ($html('a[href ^= forumdisplay] > strong') as $element) {
        echo $element->getPlainText(), "<br>\n";
    }
} else {
    foreach ($html->select('a[href ^= forumdisplay] > strong') as $element) {
        echo $element->getPlainText(), "<br>\n";
    }
}