Vsebina
- 1 Syntax
- 2 Implementations
- 3 Functions
- 3.1 esc
- 3.2 sqlq(text)
- 3.3 sqlqi(identifier_name)
- 3.4 wrap(pre,value[,post])
- 3.5 awrap(name,value)
- 3.6 xwrap(tag text, content text, attributes)
- 3.7 query(sql_statement[,arg,...])
- 3.8 iterate(handle,sub)
- 3.9 coalesce
- 3.10 nul
- 3.11 unesc
- 3.12 href( url, query, target, label, extra )
- 3.13 say, notice, error
- 3.14 logging
- 3.15 l10n
- 3.16 human_size
- 3.17 undocumented functions (some are internal)
- 3.18 really undocumented functions
Syntax
- subset of Perl and PHP
- strip off dollars for C, JavaScript and SQL
- values of variables can be undefined
Implementations
- Px (Perl) ✓
- Px (PostgreSQL) ✓
- Px (Javascript)
- Px (PHP)
- Px (Python) (volunteers?)
- Px in SQL is implemented as a part of «schema» WDBI
Functions
esc
escape a string in one of many necessary ways
esc( format, string )
Formats
- html, xml: html text escaping: <, >, &
- attr: html attribute escaping: ", <, >, &
- url, uri: all but A-Za-z0-9\-:\./ get converted to %nn;
- c, js, javascript: newline to \n, double quote
- ascii, unac: force to 8-bit (7-bit?) ascii, replacing accented characters with unaccented
- sql, sql_literal: quote and escape a value for sql. see #sqlq
- sqli, sql_identifier: quote and escape a field name for sql. see #sqlqi
- unix, file, name: munge non-ascii and whitespace for nice filenames or uris. might clash on similar inputs.
- wiki: make space-separated words into a WikiWord
- iso_date: the supplied date or today in YYYY-MM-DD format
- sh (default!?): quote with " and escape " and ' for shell
Tests
- esc(uri,'a b c') == 'a%20b%20c'
sqlq(text)
escape and quote a value for SQL. In PostgreSQL this is function quote_literal
sqlqi(identifier_name)
escape and quote an identifier (field name) for SQL. In PostgreSQL this is function quote_ident
wrap(pre,value[,post])
Wrap the value with pre and post, or return "" if the value is undefined. This is useful for attaching labels to values.
awrap(name,value)
Format the name and value as a valid XML attribute, or return "" if the value is undefined. This is useful for attaching attributes to tags when producing HTML or XML output.
awrap('src','http://foo bar.net') src="http://foo%20bar.net" awrap('src',NULL) empty string
xwrap(tag text, content text, attributes)
xwrap('li',NULL,NULL)
xwrap('li','hello','id="42"')
xwrap('li class="my_item"','bold','id="42"');
query(sql_statement[,arg,...])
Run a query. Return a statement handle (in scalar mode) or an array of values (in array mode).
iterate(handle,sub)
call the supplied sub on each value returned by handle. Handle is a sql query result handle, typically returned by the query function.
coalesce
supply alternatives for undefined values
nul
convert empty values to undefined values
unesc
reverse of esc
href( url, query, target, label, extra )
create HTML hyperlinks
select href( url, query, target, label, extra ); <a href="$url?$query" target="$target">$label</a>
say, notice, error
user-visible printing, warning, error reporting
logging
log_msg, log_err, log_warn, log_debug, log_db
l10n
translating the user interface messages
human_size
describe size of file for humans
undocumented functions (some are internal)
isset iterateA iterateH queryH queryA query_h decode flagp xwrap awrap null str_kiki str_repeat mkdirhier