@@ -33,19 +33,19 @@ discard block |
||
33 | 33 | //$url = 'http://dbpedia.org/data/The_Lord_of_the_Rings.rdf'; |
34 | 34 | // HTTP headers: |
35 | 35 | $headers = array( |
36 | - 'Accept: application/rdf,application/rdf+xml;q=0.9,*/*;q=0.8', |
|
37 | - 'Accept-Language: en-us,en', |
|
38 | - 'Accept-Charset: ISO-8859-1,utf-8', |
|
39 | - 'User-Agent: QueryPath/1.2', |
|
36 | + 'Accept: application/rdf,application/rdf+xml;q=0.9,*/*;q=0.8', |
|
37 | + 'Accept-Language: en-us,en', |
|
38 | + 'Accept-Charset: ISO-8859-1,utf-8', |
|
39 | + 'User-Agent: QueryPath/1.2', |
|
40 | 40 | ); |
41 | 41 | |
42 | 42 | // The context options: |
43 | 43 | $options = array( |
44 | - 'http' => array( |
|
44 | + 'http' => array( |
|
45 | 45 | 'method' => 'GET', |
46 | 46 | 'protocol_version' => 1.1, |
47 | 47 | 'header' => implode("\r\n", $headers), |
48 | - ), |
|
48 | + ), |
|
49 | 49 | ); |
50 | 50 | |
51 | 51 | // Create a stream context that will tell QueryPath how to |
@@ -78,21 +78,21 @@ discard block |
||
78 | 78 | |
79 | 79 | print "\nImages:\n"; |
80 | 80 | foreach ($qp->branch()->find('foaf|img') as $img) { |
81 | - // Note that when we use attr() we are using the XML name, NOT |
|
82 | - // the CSS 3 name. So it is rdf:resource, not rdf|resource. |
|
83 | - // The same goes for the tag() function -- it will return |
|
84 | - // the full element name (e.g. rdf:Description). |
|
85 | - print $img->attr('rdf:resource') . PHP_EOL; |
|
81 | + // Note that when we use attr() we are using the XML name, NOT |
|
82 | + // the CSS 3 name. So it is rdf:resource, not rdf|resource. |
|
83 | + // The same goes for the tag() function -- it will return |
|
84 | + // the full element name (e.g. rdf:Description). |
|
85 | + print $img->attr('rdf:resource') . PHP_EOL; |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | print "\nImages Galleries:\n"; |
89 | 89 | foreach ($qp->branch()->find('dbpprop|hasPhotoCollection') as $img) { |
90 | - print $img->attr('rdf:resource') . PHP_EOL; |
|
90 | + print $img->attr('rdf:resource') . PHP_EOL; |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | print "\nOther Sites:\n"; |
94 | 94 | foreach ($qp->branch()->find('foaf|page') as $img) { |
95 | - print $img->attr('rdf:resource') . PHP_EOL; |
|
95 | + print $img->attr('rdf:resource') . PHP_EOL; |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | //$qp->writeXML(); |
99 | 99 | \ No newline at end of file |
@@ -51,7 +51,7 @@ discard block |
||
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 = array( |
54 | - array( |
|
54 | + array( |
|
55 | 55 | 'title' => 'Item 1', |
56 | 56 | 'link' => 'http://example.com/item1', |
57 | 57 | 'description' => '<strong>This has embedded <em>HTML</em></strong>', |
@@ -59,8 +59,8 @@ discard block |
||
59 | 59 | 'category' => 'Some Term', |
60 | 60 | 'pubDate' => date('r'), |
61 | 61 | 'guid' => '123456-789', |
62 | - ), |
|
63 | - array( |
|
62 | + ), |
|
63 | + array( |
|
64 | 64 | 'title' => 'Item 2', |
65 | 65 | 'link' => 'http://example.com/item2', |
66 | 66 | 'description' => '<strong>This has embedded <em>HTML</em></strong>', |
@@ -68,22 +68,22 @@ discard block |
||
68 | 68 | 'category' => 'Some Other Term', |
69 | 69 | 'pubDate' => date('r'), |
70 | 70 | 'guid' => '123456-790', |
71 | - ), |
|
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 | 84 | |
85 | - // Begin with the stub RSS item, with title currently selected. |
|
86 | - $qpi = qp($rss_item_stub, 'title') |
|
85 | + // Begin with the stub RSS item, with title currently selected. |
|
86 | + $qpi = qp($rss_item_stub, 'title') |
|
87 | 87 | // Add a title. |
88 | 88 | ->text($item['title']) |
89 | 89 | // Add a link. Note that we are giving no args to next() for the |
@@ -98,8 +98,8 @@ discard block |
||
98 | 98 | ->next()->text($item['pubDate']) |
99 | 99 | ->next()->text($item['guid']); |
100 | 100 | |
101 | - // Now we append it. |
|
102 | - $qp->append($qpi->top()); |
|
101 | + // Now we append it. |
|
102 | + $qp->append($qpi->top()); |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | // If we were running this on a server, we would need to set the content |
@@ -21,7 +21,7 @@ |
||
21 | 21 | require_once '../src/QueryPath/QueryPath.php'; |
22 | 22 | |
23 | 23 | // This is the stub RSS document. |
24 | -$rss_stub ='<?xml version="1.0"?> |
|
24 | +$rss_stub = '<?xml version="1.0"?> |
|
25 | 25 | <rss version="2.0" |
26 | 26 | xmlns:dc="http://purl.org/dc/elements/1.1/"> |
27 | 27 | <channel> |
@@ -35,16 +35,16 @@ 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 | - print $element->tagName . PHP_EOL; |
|
47 | + print $element->tagName . PHP_EOL; |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | // Iterate using a callback function |
@@ -55,6 +55,6 @@ discard block |
||
55 | 55 | |
56 | 56 | // Loop through by index/count |
57 | 57 | for ($i = 0; $i < $qp->size(); ++$i) { |
58 | - $domElement = $qp->get($i); |
|
59 | - print $domElement->tagName . PHP_EOL; |
|
58 | + $domElement = $qp->get($i); |
|
59 | + print $domElement->tagName . PHP_EOL; |
|
60 | 60 | } |
61 | 61 | \ No newline at end of file |
@@ -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. |
@@ -28,10 +28,10 @@ |
||
28 | 28 | $qp = htmlqp(QueryPath::HTML_STUB, 'body'); |
29 | 29 | |
30 | 30 | |
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>'); |
|
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>'); |
|
34 | 34 | |
35 | - echo ($qp->find('p')->children('p')->html()) ? 'print' : 'dont print';; |
|
35 | + echo ($qp->find('p')->children('p')->html()) ? 'print' : 'dont print';; |
|
36 | 36 | |
37 | 37 | // ->writeHTML(); |
@@ -32,6 +32,6 @@ |
||
32 | 32 | ->children('p') |
33 | 33 | ->after('<p id="new">new paragraph</p>'); |
34 | 34 | |
35 | - echo ($qp->find('p')->children('p')->html()) ? 'print' : 'dont print';; |
|
35 | + echo ($qp->find('p')->children('p')->html()) ? 'print' : 'dont print'; ; |
|
36 | 36 | |
37 | 37 | // ->writeHTML(); |
@@ -32,11 +32,11 @@ |
||
32 | 32 | </svg>'; |
33 | 33 | |
34 | 34 | qp($svg_stub) |
35 | - ->attr(array('width' => 800, 'height' => 600)) |
|
36 | - ->append('<rect id="first"/><rect id="second"/>') |
|
37 | - ->find('#second') |
|
38 | - ->attr(array('x' => 15, 'y' => 4, 'width' => 40, 'height' => 60, 'fill' => 'red')) |
|
39 | - ->prev() |
|
40 | - ->attr(array('x' => 2, 'y' => 2, 'width' => 40, 'height' => 60, 'fill' => 'navy')) |
|
41 | - ->writeXML(); |
|
35 | + ->attr(array('width' => 800, 'height' => 600)) |
|
36 | + ->append('<rect id="first"/><rect id="second"/>') |
|
37 | + ->find('#second') |
|
38 | + ->attr(array('x' => 15, 'y' => 4, 'width' => 40, 'height' => 60, 'fill' => 'red')) |
|
39 | + ->prev() |
|
40 | + ->attr(array('x' => 2, 'y' => 2, 'width' => 40, 'height' => 60, 'fill' => 'navy')) |
|
41 | + ->writeXML(); |
|
42 | 42 |
@@ -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 | } |
55 | 55 | \ No newline at end of file |
@@ -50,5 +50,5 @@ |
||
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 | } |
55 | 55 | \ No newline at end of file |
@@ -20,8 +20,8 @@ discard block |
||
20 | 20 | $artist_url = 'http://musicbrainz.org/ws/1/artist/?type=xml&name=u2'; |
21 | 21 | $album_url = 'http://musicbrainz.org/ws/1/release/?type=xml&artistid='; |
22 | 22 | try { |
23 | - $artist = qp($artist_url, 'artist:first'); |
|
24 | - if ($artist->size() > 0) { |
|
23 | + $artist = qp($artist_url, 'artist:first'); |
|
24 | + if ($artist->size() > 0) { |
|
25 | 25 | $id = $artist->attr('id'); |
26 | 26 | print '<p>The best match we found was for ' . $artist->children('name')->text() . PHP_EOL; |
27 | 27 | print '</p><p>Artist ID: ' . $id . PHP_EOL; |
@@ -30,12 +30,12 @@ discard block |
||
30 | 30 | $albums = qp($album_url . urlencode($id))->writeXML(); |
31 | 31 | |
32 | 32 | foreach ($albums as $album) { |
33 | - print $album->find('title')->text() . PHP_EOL; |
|
34 | - // Fixme: Label is broken. See Drupal QueryPath module. |
|
35 | - print '(' . $album->next('label')->text() . ')' .PHP_EOL; |
|
33 | + print $album->find('title')->text() . PHP_EOL; |
|
34 | + // Fixme: Label is broken. See Drupal QueryPath module. |
|
35 | + print '(' . $album->next('label')->text() . ')' .PHP_EOL; |
|
36 | + } |
|
36 | 37 | } |
37 | - } |
|
38 | 38 | } |
39 | 39 | catch (Exception $e) { |
40 | - print $e->getMessage(); |
|
40 | + print $e->getMessage(); |
|
41 | 41 | } |
@@ -26,13 +26,13 @@ |
||
26 | 26 | print '<p>The best match we found was for ' . $artist->children('name')->text() . PHP_EOL; |
27 | 27 | print '</p><p>Artist ID: ' . $id . PHP_EOL; |
28 | 28 | print '</p><p>Albums for this artist' . PHP_EOL; |
29 | - print '</p><p><a href="'.$album_url . urlencode($id).'">'.$album_url.'</a></p>'; |
|
29 | + print '</p><p><a href="' . $album_url . urlencode($id) . '">' . $album_url . '</a></p>'; |
|
30 | 30 | $albums = qp($album_url . urlencode($id))->writeXML(); |
31 | 31 | |
32 | 32 | foreach ($albums as $album) { |
33 | 33 | print $album->find('title')->text() . PHP_EOL; |
34 | 34 | // Fixme: Label is broken. See Drupal QueryPath module. |
35 | - print '(' . $album->next('label')->text() . ')' .PHP_EOL; |
|
35 | + print '(' . $album->next('label')->text() . ')' . PHP_EOL; |
|
36 | 36 | } |
37 | 37 | } |
38 | 38 | } |
@@ -35,7 +35,6 @@ |
||
35 | 35 | print '(' . $album->next('label')->text() . ')' .PHP_EOL; |
36 | 36 | } |
37 | 37 | } |
38 | -} |
|
39 | -catch (Exception $e) { |
|
38 | +} catch (Exception $e) { |
|
40 | 39 | print $e->getMessage(); |
41 | 40 | } |
@@ -12,8 +12,8 @@ |
||
12 | 12 | print '<h3>Urban Dictionary Random Word Generator</h3>'; |
13 | 13 | |
14 | 14 | $page = rand(0, 288); |
15 | -$qp = htmlqp('http://www.urbandictionary.com/?page='.$page, '#home'); |
|
15 | +$qp = htmlqp('http://www.urbandictionary.com/?page=' . $page, '#home'); |
|
16 | 16 | |
17 | 17 | $rand = rand(0, 7); |
18 | -print $qp->find('.word')->eq($rand)->text().'<br />'; |
|
18 | +print $qp->find('.word')->eq($rand)->text() . '<br />'; |
|
19 | 19 | print $qp->top()->find('.definition')->eq($rand)->text(); |