Issues (146)

examples/html.php (1 issue)

1
<?php
2
/** @file
3
 * Using QueryPath.
4
 *
5
 * This file contains an example of how QueryPath can be used
6
 * to generate web pages. Part of the design of this example is to exhibit many
7
 * different QueryPath functions in one long chain. All of the methods shown 
8
 * here are fully documented in {@link QueryPath}.
9
 *
10
 * The method used in this example is a typical example of how QueryPath can 
11
 * gradually build up content. Other methods include using {@link QPTPL} for 
12
 * templates, injecting database information with {@link QPDB}, and merging
13
 * data from one QueryPath to another.
14
 *
15
 * @author M Butcher <[email protected]>
16
 * @license LGPL The GNU Lesser GPL (LGPL) or an MIT-like license.
17
 */
18
 
19
require_once '../src/qp.php';
20
21
// Begin with an HTML stub document (XHTML, actually), and navigate to the title.
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();
57
?>
0 ignored issues
show
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
58