1 Documentation of common HTML utility functions
2 ──────────────────────────────────────────────
4 Functions defined in src/common/include/utils.php → available: always.
7 • string util_html_encode(string $s)
9 util_html_secure('a=1&b=2')
10 ⇒ 'a=1&b=2' // HTML-encoded
12 util_html_secure('a=1&b=2')
13 ⇒ 'a=1&b=2' // changed!
15 Encode a string for use in XHTML even if it is already encoded.
17 • string util_html_secure(string $s)
19 util_html_secure('a=1&b=2')
20 ⇒ 'a=1&b=2' // HTML-encoded
22 util_html_secure('a=1&b=2')
23 ⇒ 'a=1&b=2' // unchanged
25 Encode a string for use in XHTML if it is not already encoded.
26 (So, if you use this for output sanitising, other than a slight
27 performance penalty no harm is done if the output was already
30 • string util_unconvert_htmlspecialchars(string $s)
32 util_unconvert_htmlspecialchars('a=1&b=2')
33 ⇒ 'a=1&b=2' // unchanged
35 util_unconvert_htmlspecialchars('a=1&b=2')
36 ⇒ 'a=1&b=2' // HTML-decoded
38 Undo util_html_encode; be careful, this can decode partially.
41 • string util_gethref(optional(false) string $baseurl,
42 optional(empty) array $args, optional(true) bool $ashtml,
43 optional('&') string $sep)
45 util_gethref("/x.php", array(
49 ⇒ "/x.php?foo=a%2Bb%26c&bar=d%2Bb%26e"
51 util_gethref("/x.php", array(
55 ⇒ /x.php?foo=a%2Bb%26c&bar=d%2Bb%26e
57 util_gethref("/x.php", array(
61 ⇒ "/x.php?foo=a%2Bb%26c;bar=d%2Bb%26e"
63 Construct an URI for use with util_make_url, session_redirect,
64 html_e('a', array('href' => …)), and similar. The first argument
65 ($baseurl) is passed through as-is but, if falsy, defaults to
66 getStringFromServer('PHP_SELF'); the arguments (both keys and
67 values) are urlencoded (entries while values is false are not
68 emitted at all) and appended, with a question mark in front and
69 the $sep separator in between.
71 If $ashtml is true (default), the result will then be run through
72 util_html_encode; set this to false when using in html_e href as
73 value (since html_e will html-encode itself).
75 • string util_make_url(string $path)
77 util_make_url('/foo.php?a=1&b=2')
78 ⇒ 'https://forge.domain.com/fusionforge/foo.php?a=1&b=2'
80 Return an absolute URI for the path in question, containing the
81 system-defined protocol, hostname and (if defined) webroot prefix.
83 Both html-encoded and not html-encoded return values of util_gethref
84 are safe to pass as arguments, if their baseurl was only a path.
86 • integer|false util_nat0(ByRef string $s)
88 If and only if $s is the normalised positive integer (ℕ₀)
89 representation of a number, return that number; false otherwise.
90 Limited by system constraints, i.e. usually [0;2³¹-1].
93 ‣ common non-HTML utility functions
96 • mixed util_ifsetor(ByRef mixed $val, optional(false) mixed $default)
98 If isset($val), return $val, otherwise (no warning) $default.
100 • string debug_string_backtrace(void)
102 Return the current debugging backtrace as string.