Društvo LJUDMILA
Rozmanova ulica 12
1000 Ljubljana
Slovenia
Prostori: osmo/za

Px API

Syntax

  • subset of Perl and PHP
  • strip off dollars for C, JavaScript and SQL
  • values of variables can be undefined

Implementations

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',NULL)
  • hello
  • xwrap('li','hello','id="42"')
    
  • hello
  • xwrap('li class="my_item"','bold','id="42"');
    
  • bold
  • 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

    really undocumented functions

    Not documented yet. ;)