@@ -17,34 +17,34 @@ |
||
| 17 | 17 | class ParseException extends Exception |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - public const ERR_MSG_FORMAT = 'Parse error in %s on line %d column %d: %s (%d)'; |
|
| 21 | - public const WARN_MSG_FORMAT = 'Parser warning in %s on line %d column %d: %s (%d)'; |
|
| 22 | - |
|
| 23 | - // trigger_error |
|
| 24 | - public function __construct($msg = '', $code = 0, $file = null, $line = null) |
|
| 25 | - { |
|
| 26 | - |
|
| 27 | - $msgs = []; |
|
| 28 | - foreach (libxml_get_errors() as $err) { |
|
| 29 | - $format = $err->level === LIBXML_ERR_WARNING ? self::WARN_MSG_FORMAT : self::ERR_MSG_FORMAT; |
|
| 30 | - $msgs[] = sprintf($format, $err->file, $err->line, $err->column, $err->message, $err->code); |
|
| 31 | - } |
|
| 32 | - $msg .= implode("\n", $msgs); |
|
| 33 | - |
|
| 34 | - if (isset($file)) { |
|
| 35 | - $msg .= ' (' . $file; |
|
| 36 | - if (isset($line)) { |
|
| 37 | - $msg .= ': ' . $line; |
|
| 38 | - } |
|
| 39 | - $msg .= ')'; |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - parent::__construct($msg, $code); |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - public static function initializeFromError($errno, $errstr, $errfile, $errline, $context = null) |
|
| 46 | - { |
|
| 47 | - $class = __CLASS__; |
|
| 48 | - throw new $class($errno, (int) $errstr, $errfile, $errline); |
|
| 49 | - } |
|
| 20 | + public const ERR_MSG_FORMAT = 'Parse error in %s on line %d column %d: %s (%d)'; |
|
| 21 | + public const WARN_MSG_FORMAT = 'Parser warning in %s on line %d column %d: %s (%d)'; |
|
| 22 | + |
|
| 23 | + // trigger_error |
|
| 24 | + public function __construct($msg = '', $code = 0, $file = null, $line = null) |
|
| 25 | + { |
|
| 26 | + |
|
| 27 | + $msgs = []; |
|
| 28 | + foreach (libxml_get_errors() as $err) { |
|
| 29 | + $format = $err->level === LIBXML_ERR_WARNING ? self::WARN_MSG_FORMAT : self::ERR_MSG_FORMAT; |
|
| 30 | + $msgs[] = sprintf($format, $err->file, $err->line, $err->column, $err->message, $err->code); |
|
| 31 | + } |
|
| 32 | + $msg .= implode("\n", $msgs); |
|
| 33 | + |
|
| 34 | + if (isset($file)) { |
|
| 35 | + $msg .= ' (' . $file; |
|
| 36 | + if (isset($line)) { |
|
| 37 | + $msg .= ': ' . $line; |
|
| 38 | + } |
|
| 39 | + $msg .= ')'; |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + parent::__construct($msg, $code); |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + public static function initializeFromError($errno, $errstr, $errfile, $errline, $context = null) |
|
| 46 | + { |
|
| 47 | + $class = __CLASS__; |
|
| 48 | + throw new $class($errno, (int) $errstr, $errfile, $errline); |
|
| 49 | + } |
|
| 50 | 50 | } |
@@ -45,6 +45,6 @@ |
||
| 45 | 45 | public static function initializeFromError($errno, $errstr, $errfile, $errline, $context = null) |
| 46 | 46 | { |
| 47 | 47 | $class = __CLASS__; |
| 48 | - throw new $class($errno, (int) $errstr, $errfile, $errline); |
|
| 48 | + throw new $class($errno, (int)$errstr, $errfile, $errline); |
|
| 49 | 49 | } |
| 50 | 50 | } |
@@ -29,8 +29,8 @@ |
||
| 29 | 29 | |
| 30 | 30 | |
| 31 | 31 | $qp->append('<div></div><p id="cool">Hello</p><p id="notcool">Goodbye</p>') |
| 32 | - ->children('p') |
|
| 33 | - ->after('<p id="new">new paragraph</p>'); |
|
| 32 | + ->children('p') |
|
| 33 | + ->after('<p id="new">new paragraph</p>'); |
|
| 34 | 34 | |
| 35 | 35 | echo ($qp->find('p')->children('p')->html()) ? 'print' : 'dont print'; |
| 36 | 36 | |
@@ -26,30 +26,30 @@ |
||
| 26 | 26 | // By default, it will point to the root element, |
| 27 | 27 | // <author/> |
| 28 | 28 | $record = qp('<?xml version="1.0"?><author></author>') |
| 29 | - // Add a new last name inside of author. |
|
| 30 | - ->append('<lastName>Dostoyevsky</lastName>') |
|
| 31 | - // Select all of the children of <author/>. In this case, |
|
| 32 | - // that is <lastName/> |
|
| 33 | - ->children() |
|
| 34 | - // Oh, wait... we wanted last name to be inside of a <name/> |
|
| 35 | - // element. Use wrap to wrap the current element in something: |
|
| 36 | - ->wrap('<name/>') |
|
| 37 | - // And before last name, we want to add first name. |
|
| 38 | - ->before('<firstName/>') |
|
| 39 | - // Select first name |
|
| 40 | - ->prev() |
|
| 41 | - // Set the text of first name |
|
| 42 | - ->text('Fyodor') |
|
| 43 | - // And then after first name, add the patronymic |
|
| 44 | - ->after('<patronymic>Fyodorovich</patronymic>') |
|
| 45 | - // Now go back to the root element, the top of the document. |
|
| 46 | - ->top() |
|
| 47 | - // Add another tag -- origin. |
|
| 48 | - ->append('<origin>Russia</origin>') |
|
| 49 | - // turn the QueryPath contents back into a string. Since we are |
|
| 50 | - // at the top of the document, the whole document will be converted |
|
| 51 | - // to a string. |
|
| 52 | - ->xml(); |
|
| 29 | + // Add a new last name inside of author. |
|
| 30 | + ->append('<lastName>Dostoyevsky</lastName>') |
|
| 31 | + // Select all of the children of <author/>. In this case, |
|
| 32 | + // that is <lastName/> |
|
| 33 | + ->children() |
|
| 34 | + // Oh, wait... we wanted last name to be inside of a <name/> |
|
| 35 | + // element. Use wrap to wrap the current element in something: |
|
| 36 | + ->wrap('<name/>') |
|
| 37 | + // And before last name, we want to add first name. |
|
| 38 | + ->before('<firstName/>') |
|
| 39 | + // Select first name |
|
| 40 | + ->prev() |
|
| 41 | + // Set the text of first name |
|
| 42 | + ->text('Fyodor') |
|
| 43 | + // And then after first name, add the patronymic |
|
| 44 | + ->after('<patronymic>Fyodorovich</patronymic>') |
|
| 45 | + // Now go back to the root element, the top of the document. |
|
| 46 | + ->top() |
|
| 47 | + // Add another tag -- origin. |
|
| 48 | + ->append('<origin>Russia</origin>') |
|
| 49 | + // turn the QueryPath contents back into a string. Since we are |
|
| 50 | + // at the top of the document, the whole document will be converted |
|
| 51 | + // to a string. |
|
| 52 | + ->xml(); |
|
| 53 | 53 | |
| 54 | 54 | // Print our results. |
| 55 | 55 | print $record; |
@@ -20,15 +20,15 @@ discard block |
||
| 20 | 20 | |
| 21 | 21 | |
| 22 | 22 | foreach (qp($path, 'w|p') as $qp) { |
| 23 | - $qr = $qp->branch(); |
|
| 24 | - print format($qr->find('w|r:first'), 'w|r:first') . ' '; |
|
| 25 | - $qp->find('w|r:first'); |
|
| 26 | - while ($qp->next('w|r')->html() != null) { |
|
| 27 | - $qr = $qp->branch(); |
|
| 28 | - print format($qr->find('w|r'), 'w|r') . ' '; |
|
| 29 | - // print $qp->text(); |
|
| 30 | - } |
|
| 31 | - print '</br>'; |
|
| 23 | + $qr = $qp->branch(); |
|
| 24 | + print format($qr->find('w|r:first'), 'w|r:first') . ' '; |
|
| 25 | + $qp->find('w|r:first'); |
|
| 26 | + while ($qp->next('w|r')->html() != null) { |
|
| 27 | + $qr = $qp->branch(); |
|
| 28 | + print format($qr->find('w|r'), 'w|r') . ' '; |
|
| 29 | + // print $qp->text(); |
|
| 30 | + } |
|
| 31 | + print '</br>'; |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | /** |
@@ -41,17 +41,17 @@ discard block |
||
| 41 | 41 | function format($qp, $findSelector = null) |
| 42 | 42 | { |
| 43 | 43 | |
| 44 | - // Create a new branch for printing later. |
|
| 45 | - $qr = $qp->branch(); |
|
| 44 | + // Create a new branch for printing later. |
|
| 45 | + $qr = $qp->branch(); |
|
| 46 | 46 | |
| 47 | - $text = ""; |
|
| 47 | + $text = ""; |
|
| 48 | 48 | |
| 49 | - $text = $qr->find($findSelector)->find('w|t')->text(); |
|
| 49 | + $text = $qr->find($findSelector)->find('w|t')->text(); |
|
| 50 | 50 | |
| 51 | - $text = (checkUnderline($qp->branch())) ? '<u>' . $text . '</u>' : $text; |
|
| 52 | - $text = (checkBold($qp->branch())) ? '<b>' . $text . '</b>' : $text; |
|
| 51 | + $text = (checkUnderline($qp->branch())) ? '<u>' . $text . '</u>' : $text; |
|
| 52 | + $text = (checkBold($qp->branch())) ? '<b>' . $text . '</b>' : $text; |
|
| 53 | 53 | |
| 54 | - return $text; |
|
| 54 | + return $text; |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | /** |
@@ -62,9 +62,9 @@ discard block |
||
| 62 | 62 | */ |
| 63 | 63 | function checkBold($qp) |
| 64 | 64 | { |
| 65 | - $qp->children("w|rPr"); |
|
| 65 | + $qp->children("w|rPr"); |
|
| 66 | 66 | |
| 67 | - return ($qp->children('w|b')->html()) ? true : false; |
|
| 67 | + return ($qp->children('w|b')->html()) ? true : false; |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | /** |
@@ -75,42 +75,42 @@ discard block |
||
| 75 | 75 | */ |
| 76 | 76 | function checkUnderline($qp) |
| 77 | 77 | { |
| 78 | - $qp->children("w|rPr"); |
|
| 78 | + $qp->children("w|rPr"); |
|
| 79 | 79 | |
| 80 | - return ($qp->children('w|u')->html()) ? true : false; |
|
| 80 | + return ($qp->children('w|u')->html()) ? true : false; |
|
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | |
| 84 | 84 | function docx2text($filename) |
| 85 | 85 | { |
| 86 | - return readZippedXML($filename, "word/document.xml"); |
|
| 86 | + return readZippedXML($filename, "word/document.xml"); |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | function readZippedXML($archiveFile, $dataFile) |
| 90 | 90 | { |
| 91 | - if (! class_exists('ZipArchive', false)) { |
|
| 92 | - return "ZipArchive Class Doesn't Exist."; |
|
| 93 | - } |
|
| 94 | - // Create new ZIP archive |
|
| 95 | - $zip = new ZipArchive(); |
|
| 96 | - // Open received archive file |
|
| 97 | - if (true === $zip->open($archiveFile)) { |
|
| 98 | - // If done, search for the data file in the archive |
|
| 99 | - if (($index = $zip->locateName($dataFile)) !== false) { |
|
| 100 | - // If found, read it to the string |
|
| 101 | - $data = $zip->getFromIndex($index); |
|
| 102 | - // Close archive file |
|
| 103 | - $zip->close(); |
|
| 104 | - // Load XML from a string |
|
| 105 | - // Skip errors and warnings |
|
| 106 | - return $data; |
|
| 107 | - // $xml = DOMDocument::loadXML($data, LIBXML_NOENT | LIBXML_XINCLUDE | LIBXML_NOERROR | LIBXML_NOWARNING); |
|
| 108 | - // // Return data without XML formatting tags |
|
| 109 | - // return strip_tags($xml->saveXML()); |
|
| 110 | - } |
|
| 111 | - $zip->close(); |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - // In case of failure return empty string |
|
| 115 | - return $zip->getStatusString(); |
|
| 91 | + if (! class_exists('ZipArchive', false)) { |
|
| 92 | + return "ZipArchive Class Doesn't Exist."; |
|
| 93 | + } |
|
| 94 | + // Create new ZIP archive |
|
| 95 | + $zip = new ZipArchive(); |
|
| 96 | + // Open received archive file |
|
| 97 | + if (true === $zip->open($archiveFile)) { |
|
| 98 | + // If done, search for the data file in the archive |
|
| 99 | + if (($index = $zip->locateName($dataFile)) !== false) { |
|
| 100 | + // If found, read it to the string |
|
| 101 | + $data = $zip->getFromIndex($index); |
|
| 102 | + // Close archive file |
|
| 103 | + $zip->close(); |
|
| 104 | + // Load XML from a string |
|
| 105 | + // Skip errors and warnings |
|
| 106 | + return $data; |
|
| 107 | + // $xml = DOMDocument::loadXML($data, LIBXML_NOENT | LIBXML_XINCLUDE | LIBXML_NOERROR | LIBXML_NOWARNING); |
|
| 108 | + // // Return data without XML formatting tags |
|
| 109 | + // return strip_tags($xml->saveXML()); |
|
| 110 | + } |
|
| 111 | + $zip->close(); |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + // In case of failure return empty string |
|
| 115 | + return $zip->getStatusString(); |
|
| 116 | 116 | } |
@@ -88,7 +88,7 @@ |
||
| 88 | 88 | |
| 89 | 89 | function readZippedXML($archiveFile, $dataFile) |
| 90 | 90 | { |
| 91 | - if (! class_exists('ZipArchive', false)) { |
|
| 91 | + if (!class_exists('ZipArchive', false)) { |
|
| 92 | 92 | return "ZipArchive Class Doesn't Exist."; |
| 93 | 93 | } |
| 94 | 94 | // Create new ZIP archive |
@@ -35,17 +35,17 @@ discard block |
||
| 35 | 35 | |
| 36 | 36 | // Iterate over elements as DOMNodes: |
| 37 | 37 | foreach ($qp->get() as $li_ele) { |
| 38 | - print $li_ele->tagName . PHP_EOL; // Prints 'li' five times. |
|
| 38 | + print $li_ele->tagName . PHP_EOL; // Prints 'li' five times. |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | // Iterate over elements as QueryPath objects |
| 42 | 42 | foreach ($qp as $li_qp) { |
| 43 | - print $li_qp->tag() . PHP_EOL; // Prints 'li' five times |
|
| 43 | + print $li_qp->tag() . PHP_EOL; // Prints 'li' five times |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | function callbackFunction($index, $element) |
| 47 | 47 | { |
| 48 | - print $element->tagName . PHP_EOL; |
|
| 48 | + print $element->tagName . PHP_EOL; |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | // Iterate using a callback function |
@@ -56,6 +56,6 @@ discard block |
||
| 56 | 56 | |
| 57 | 57 | // Loop through by index/count |
| 58 | 58 | for ($i = 0; $i < $qp->size(); ++$i) { |
| 59 | - $domElement = $qp->get($i); |
|
| 60 | - print $domElement->tagName . PHP_EOL; |
|
| 59 | + $domElement = $qp->get($i); |
|
| 60 | + print $domElement->tagName . PHP_EOL; |
|
| 61 | 61 | } |
@@ -20,37 +20,37 @@ |
||
| 20 | 20 | |
| 21 | 21 | // Begin with an HTML stub document (XHTML, actually), and navigate to the title. |
| 22 | 22 | qp(QueryPath::HTML_STUB, 'title') |
| 23 | - // Add some text to the title |
|
| 24 | - ->text('Example of QueryPath.') |
|
| 25 | - // Now look for the <body> element |
|
| 26 | - ->top('body') |
|
| 27 | - // Inside the body, add a title and paragraph. |
|
| 28 | - ->append('<h1>This is a test page</h1><p>Test text</p>') |
|
| 29 | - // Now we select the paragraph we just created inside the body |
|
| 30 | - ->children('p') |
|
| 31 | - // Add a 'class="some-class"' attribute to the paragraph |
|
| 32 | - ->attr('class', 'some-class') |
|
| 33 | - // And add a style attribute, too, setting the background color. |
|
| 34 | - ->css('background-color', '#eee') |
|
| 35 | - // Now go back to the paragraph again |
|
| 36 | - ->parent() |
|
| 37 | - // Before the paragraph and the title, add an empty table. |
|
| 38 | - ->prepend('<table id="my-table"></table>') |
|
| 39 | - // Now let's go to the table... |
|
| 40 | - ->top('#my-table') |
|
| 41 | - // Add a couple of empty rows |
|
| 42 | - ->append('<tr></tr><tr></tr>') |
|
| 43 | - // select the rows (both at once) |
|
| 44 | - ->children() |
|
| 45 | - // Add a CSS class to both rows |
|
| 46 | - ->addClass('table-row') |
|
| 47 | - // Now just get the first row (at position 0) |
|
| 48 | - ->eq(0) |
|
| 49 | - // Add a table header in the first row |
|
| 50 | - ->append('<th>This is the header</th>') |
|
| 51 | - // Now go to the next row |
|
| 52 | - ->next() |
|
| 53 | - // Add some data to this row |
|
| 54 | - ->append('<td>This is the data</td>') |
|
| 55 | - // Write it all out as HTML |
|
| 56 | - ->writeHTML(); |
|
| 23 | + // Add some text to the title |
|
| 24 | + ->text('Example of QueryPath.') |
|
| 25 | + // Now look for the <body> element |
|
| 26 | + ->top('body') |
|
| 27 | + // Inside the body, add a title and paragraph. |
|
| 28 | + ->append('<h1>This is a test page</h1><p>Test text</p>') |
|
| 29 | + // Now we select the paragraph we just created inside the body |
|
| 30 | + ->children('p') |
|
| 31 | + // Add a 'class="some-class"' attribute to the paragraph |
|
| 32 | + ->attr('class', 'some-class') |
|
| 33 | + // And add a style attribute, too, setting the background color. |
|
| 34 | + ->css('background-color', '#eee') |
|
| 35 | + // Now go back to the paragraph again |
|
| 36 | + ->parent() |
|
| 37 | + // Before the paragraph and the title, add an empty table. |
|
| 38 | + ->prepend('<table id="my-table"></table>') |
|
| 39 | + // Now let's go to the table... |
|
| 40 | + ->top('#my-table') |
|
| 41 | + // Add a couple of empty rows |
|
| 42 | + ->append('<tr></tr><tr></tr>') |
|
| 43 | + // select the rows (both at once) |
|
| 44 | + ->children() |
|
| 45 | + // Add a CSS class to both rows |
|
| 46 | + ->addClass('table-row') |
|
| 47 | + // Now just get the first row (at position 0) |
|
| 48 | + ->eq(0) |
|
| 49 | + // Add a table header in the first row |
|
| 50 | + ->append('<th>This is the header</th>') |
|
| 51 | + // Now go to the next row |
|
| 52 | + ->next() |
|
| 53 | + // Add some data to this row |
|
| 54 | + ->append('<td>This is the data</td>') |
|
| 55 | + // Write it all out as HTML |
|
| 56 | + ->writeHTML(); |
|
@@ -51,54 +51,54 @@ |
||
| 51 | 51 | // simplicity, we are just using a nested array. Of |
| 52 | 52 | // course, this could be a database lookup or whatever. |
| 53 | 53 | $items = [ |
| 54 | - [ |
|
| 55 | - 'title' => 'Item 1', |
|
| 56 | - 'link' => 'http://example.com/item1', |
|
| 57 | - 'description' => '<strong>This has embedded <em>HTML</em></strong>', |
|
| 58 | - 'comments' => 'http://example.com/item1/comments', |
|
| 59 | - 'category' => 'Some Term', |
|
| 60 | - 'pubDate' => date('r'), |
|
| 61 | - 'guid' => '123456-789', |
|
| 62 | - ], |
|
| 63 | - [ |
|
| 64 | - 'title' => 'Item 2', |
|
| 65 | - 'link' => 'http://example.com/item2', |
|
| 66 | - 'description' => '<strong>This has embedded <em>HTML</em></strong>', |
|
| 67 | - 'comments' => 'http://example.com/item2/comments', |
|
| 68 | - 'category' => 'Some Other Term', |
|
| 69 | - 'pubDate' => date('r'), |
|
| 70 | - 'guid' => '123456-790', |
|
| 71 | - ], |
|
| 54 | + [ |
|
| 55 | + 'title' => 'Item 1', |
|
| 56 | + 'link' => 'http://example.com/item1', |
|
| 57 | + 'description' => '<strong>This has embedded <em>HTML</em></strong>', |
|
| 58 | + 'comments' => 'http://example.com/item1/comments', |
|
| 59 | + 'category' => 'Some Term', |
|
| 60 | + 'pubDate' => date('r'), |
|
| 61 | + 'guid' => '123456-789', |
|
| 62 | + ], |
|
| 63 | + [ |
|
| 64 | + 'title' => 'Item 2', |
|
| 65 | + 'link' => 'http://example.com/item2', |
|
| 66 | + 'description' => '<strong>This has embedded <em>HTML</em></strong>', |
|
| 67 | + 'comments' => 'http://example.com/item2/comments', |
|
| 68 | + 'category' => 'Some Other Term', |
|
| 69 | + 'pubDate' => date('r'), |
|
| 70 | + 'guid' => '123456-790', |
|
| 71 | + ], |
|
| 72 | 72 | ]; |
| 73 | 73 | |
| 74 | 74 | // The main QueryPath, which holds the channel. |
| 75 | 75 | $qp = qp($rss_stub, 'title') |
| 76 | - ->text('A QueryPath RSS Feed') |
|
| 77 | - ->next('link')->text('http://example.com') |
|
| 78 | - ->next('description')->text('QueryPath: Find your way.') |
|
| 79 | - ->parent(); |
|
| 76 | + ->text('A QueryPath RSS Feed') |
|
| 77 | + ->next('link')->text('http://example.com') |
|
| 78 | + ->next('description')->text('QueryPath: Find your way.') |
|
| 79 | + ->parent(); |
|
| 80 | 80 | |
| 81 | 81 | // For each element in the array above, we create a new |
| 82 | 82 | // QueryPath and then populate the XML fragment with data. |
| 83 | 83 | foreach ($items as $item) { |
| 84 | - // Begin with the stub RSS item, with title currently selected. |
|
| 85 | - $qpi = qp($rss_item_stub, 'title') |
|
| 86 | - // Add a title. |
|
| 87 | - ->text($item['title']) |
|
| 88 | - // Add a link. Note that we are giving no args to next() for the |
|
| 89 | - // sake of simplicity. |
|
| 90 | - ->next()->text($item['link']) |
|
| 91 | - // Go to next element and add a description. Note that the text() |
|
| 92 | - // call will automatically encode HTML. < will become < and so on. |
|
| 93 | - ->next()->text($item['description']) |
|
| 94 | - // Go on down the list... |
|
| 95 | - ->next()->text($item['comments']) |
|
| 96 | - ->next()->text($item['category']) |
|
| 97 | - ->next()->text($item['pubDate']) |
|
| 98 | - ->next()->text($item['guid']); |
|
| 84 | + // Begin with the stub RSS item, with title currently selected. |
|
| 85 | + $qpi = qp($rss_item_stub, 'title') |
|
| 86 | + // Add a title. |
|
| 87 | + ->text($item['title']) |
|
| 88 | + // Add a link. Note that we are giving no args to next() for the |
|
| 89 | + // sake of simplicity. |
|
| 90 | + ->next()->text($item['link']) |
|
| 91 | + // Go to next element and add a description. Note that the text() |
|
| 92 | + // call will automatically encode HTML. < will become < and so on. |
|
| 93 | + ->next()->text($item['description']) |
|
| 94 | + // Go on down the list... |
|
| 95 | + ->next()->text($item['comments']) |
|
| 96 | + ->next()->text($item['category']) |
|
| 97 | + ->next()->text($item['pubDate']) |
|
| 98 | + ->next()->text($item['guid']); |
|
| 99 | 99 | |
| 100 | - // Now we append it. |
|
| 101 | - $qp->append($qpi->top()); |
|
| 100 | + // Now we append it. |
|
| 101 | + $qp->append($qpi->top()); |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | // If we were running this on a server, we would need to set the content |
@@ -29,11 +29,11 @@ discard block |
||
| 29 | 29 | |
| 30 | 30 | // Show the "outline": all of the heading items: |
| 31 | 31 | foreach ($doc->find('text|h') as $header) { |
| 32 | - $style = $header->attr('text:style-name'); |
|
| 33 | - $attr_parts = explode('_', $style); |
|
| 34 | - $level = array_pop($attr_parts); |
|
| 35 | - $out = str_repeat(' ', $level) . '- ' . $header->text(); |
|
| 36 | - print $out . PHP_EOL; |
|
| 32 | + $style = $header->attr('text:style-name'); |
|
| 33 | + $attr_parts = explode('_', $style); |
|
| 34 | + $level = array_pop($attr_parts); |
|
| 35 | + $out = str_repeat(' ', $level) . '- ' . $header->text(); |
|
| 36 | + print $out . PHP_EOL; |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | // This is a fairly sophisticated selector. It gets the first |
@@ -44,11 +44,11 @@ discard block |
||
| 44 | 44 | |
| 45 | 45 | print PHP_EOL . "Bullet List" . PHP_EOL; |
| 46 | 46 | foreach ($doc->top()->find($selector) as $bullet) { |
| 47 | - print ' * ' . $bullet->text() . PHP_EOL; |
|
| 47 | + print ' * ' . $bullet->text() . PHP_EOL; |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | print PHP_EOL . "Ordered List" . PHP_EOL; |
| 51 | 51 | $i = 0; |
| 52 | 52 | foreach ($doc->top()->find('text|list[text|style-name="L2"]:first text|p[text|style-name="P2"]') as $bullet) { |
| 53 | - print ' ' . (++$i) . '. ' . $bullet->text() . PHP_EOL; |
|
| 53 | + print ' ' . (++$i) . '. ' . $bullet->text() . PHP_EOL; |
|
| 54 | 54 | } |
@@ -22,23 +22,23 @@ |
||
| 22 | 22 | |
| 23 | 23 | // We will write the results into this document. |
| 24 | 24 | $out = qp(QueryPath::HTML_STUB, 'title') |
| 25 | - ->text('RSS Titles') |
|
| 26 | - ->top() |
|
| 27 | - ->find('body') |
|
| 28 | - ->append('<ul/>') |
|
| 29 | - ->children('ul'); |
|
| 25 | + ->text('RSS Titles') |
|
| 26 | + ->top() |
|
| 27 | + ->find('body') |
|
| 28 | + ->append('<ul/>') |
|
| 29 | + ->children('ul'); |
|
| 30 | 30 | |
| 31 | 31 | // Load the remote document and loop through all of the items. |
| 32 | 32 | foreach (qp($remote, 'channel>item') as $item) { |
| 33 | - // Get title and link. |
|
| 34 | - $title = $item->find('title')->text(); |
|
| 35 | - $link = $item->next('link')->text(); |
|
| 33 | + // Get title and link. |
|
| 34 | + $title = $item->find('title')->text(); |
|
| 35 | + $link = $item->next('link')->text(); |
|
| 36 | 36 | |
| 37 | - // Do a little string building. |
|
| 38 | - $bullet = '<li><a href="' . htmlspecialchars($link, ENT_QUOTES, 'UTF-8') . '">' . $title . '</a></li>'; |
|
| 37 | + // Do a little string building. |
|
| 38 | + $bullet = '<li><a href="' . htmlspecialchars($link, ENT_QUOTES, 'UTF-8') . '">' . $title . '</a></li>'; |
|
| 39 | 39 | |
| 40 | - // Add it to the output document. |
|
| 41 | - $out->append($bullet); |
|
| 40 | + // Add it to the output document. |
|
| 41 | + $out->append($bullet); |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | // Write the results. |