$select->append_child(new AnewtXHTMLOption('Second', array('value' => 'second'))); $select->append_child(new AnewtXHTMLOption('Third', array('value' => 'third'))); $form->append_child(new AnewtXHTMLParagraph($select)); $fragment->append_child($form); $form->append_child(new AnewtXHTMLParagraph(new AnewtXHTMLInput(null, array('type' => 'submit')))); /* Convenience API */ $r = array(); $r[] = ax_h2('Convenience API'); $r[] = ax_p('Test with some <& special characters.', array('style' => 'color: #ccc;')); $r[] = ax_p_class(ax_raw('This is <strong>strong</strong>'), 'someclass'); $r[] = ax_p(ax_abbr('ICE', 'InterCity Express')); $r[] = ax_p(array('Test', ax_br(), 'after the break')); $p = ax_p(array('testje', array('1', '2'), ax_strong('blablabla'))); $p->set_attribute('id', 'paragraph-id'); $p->set_class('foo bar baz'); $p->remove_class('bar'); $p->add_class('quux'); $p->append_child(ax_a_href('name', '/url/')); $r[] = $p; $r[] = ax_p(ax_sprintf('%s & %s', ax_span_class('Sugar', 'sweet'), 'Spice')); $r[] = ax_p(ax_vsprintf('%s & %s', array(ax_span_class('Sugar', 'sweet'), 'Spice'))); $values = array('this', ax_strong('is'), 'a', ax_span('test')); $r[] = ax_p(ax_join(', ', $values)); $r[] = ax_p(ax_join(ax_em(' & '), $values)); $fragment->append_child(ax_fragment($r, ax_p('final paragraph'))); /* Final output */ anewt_include('page'); $page = new AnewtPage(); $page->title = 'Anewt XHTML output test'; $page->append($fragment); $page->flush();
/** * Join array elements with a string or DOM node. * * This is an XHTML-aware version of the built-in join() function. * * \param $glue * The glue string (or DOM node) to insert between each subsequent pair of * values. * * \param $values * The values to join together. These can be strings or DOM nodes. * * \return * A DOM node instance containing the joined values. */ function ax_join($glue, $values) { assert('is_numeric_array($values);'); /* Make sure the glue is escaped properly */ if ($glue instanceof AnewtXMLDomNode) { $glue = to_string($glue); } else { assert('is_string($glue)'); $glue = htmlspecialchars($glue); } /* Build a format string so that ax_vsprintf() can do the real work */ $glue = str_replace('%', '%%', $glue); $format = join($glue, array_fill(0, count($values), '%s')); return ax_vsprintf(ax_raw($format), $values); }