Bearsampp 2026.9.23
Loading...
Searching...
No Matches
XML_Util Class Reference

Static Public Member Functions

static apiVersion ()
static attributesToString ( $attributes, $sort=true, $multiline=false, $indent=' ', $linebreak="\n", $entities=XML_UTIL_ENTITIES_XML)
static collapseEmptyTags ($xml, $mode=XML_UTIL_COLLAPSE_ALL)
static createCDataSection ($data)
static createComment ($content)
static createEndElement ($qname)
static createStartElement ( $qname, $attributes=array(), $namespaceUri=null, $multiline=false, $indent='_auto', $linebreak="\n", $sortAttributes=true)
static createTag ( $qname, $attributes=array(), $content=null, $namespaceUri=null, $replaceEntities=XML_UTIL_REPLACE_ENTITIES, $multiline=false, $indent='_auto', $linebreak="\n", $sortAttributes=true, $collapseTagMode=XML_UTIL_COLLAPSE_ALL)
static createTagFromArray ( $tag, $replaceEntities=XML_UTIL_REPLACE_ENTITIES, $multiline=false, $indent='_auto', $linebreak="\n", $sortAttributes=true, $collapseTagMode=XML_UTIL_COLLAPSE_ALL)
static getDocTypeDeclaration ( $root, $uri=null, $internalDtd=null)
static getXMLDeclaration ( $version='1.0', $encoding=null, $standalone=null)
static isValidName ($string)
static raiseError ($msg, $code)
static replaceEntities ( $string, $replaceEntities=XML_UTIL_ENTITIES_XML, $encoding='ISO-8859-1')
static reverseEntities ( $string, $replaceEntities=XML_UTIL_ENTITIES_XML, $encoding='ISO-8859-1')
static splitQualifiedName ($qname, $defaultNs=null)

Detailed Description

Definition at line 126 of file Util.php.

Member Function Documentation

◆ apiVersion()

apiVersion ( )
static

Return API version

Returns
string $version API version

Definition at line 133 of file Util.php.

134 {
135 return '1.4';
136 }

◆ attributesToString()

attributesToString ( $attributes,
$sort = true,
$multiline = false,
$indent = '    ',
$linebreak = "\n",
$entities = XML_UTIL_ENTITIES_XML )
static

Create string representation of an attribute list

require_once 'XML/Util.php';

// build an attribute string $att = array( 'foo' => 'bar', 'argh' => 'tomato' );

$attList = XML_Util\attributesToString($att);

Parameters
array$attributesattribute array
bool | array$sortsort attribute list alphabetically, may also be an assoc array containing the keys 'sort', 'multiline', 'indent', 'linebreak' and 'entities'
bool$multilineuse linebreaks, if more than one attribute is given
string$indentstring used for indentation of multiline attributes
string$linebreakstring used for linebreaks of multiline attributes
int$entitiessetting for entities in attribute values (one of XML_UTIL_ENTITIES_NONE, XML_UTIL_ENTITIES_XML, XML_UTIL_ENTITIES_XML_REQUIRED, XML_UTIL_ENTITIES_HTML)
Returns
string string representation of the attributes @uses replaceEntities() to replace XML entities in attribute values
Todo
allow sort also to be an options array

Definition at line 392 of file Util.php.

395 {
396 /*
397 * second parameter may be an array
398 */
399 if (is_array($sort)) {
400 if (isset($sort['multiline'])) {
401 $multiline = $sort['multiline'];
402 }
403 if (isset($sort['indent'])) {
404 $indent = $sort['indent'];
405 }
406 if (isset($sort['linebreak'])) {
407 $multiline = $sort['linebreak'];
408 }
409 if (isset($sort['entities'])) {
410 $entities = $sort['entities'];
411 }
412 if (isset($sort['sort'])) {
413 $sort = $sort['sort'];
414 } else {
415 $sort = true;
416 }
417 }
418 $string = '';
419 if (is_array($attributes) && !empty($attributes)) {
420 if ($sort) {
421 ksort($attributes);
422 }
423 if (!$multiline || count($attributes) == 1) {
424 foreach ($attributes as $key => $value) {
425 if ($entities != XML_UTIL_ENTITIES_NONE) {
426 if ($entities === XML_UTIL_CDATA_SECTION) {
427 $entities = XML_UTIL_ENTITIES_XML;
428 }
429 $value = XML_Util::replaceEntities($value, $entities);
430 }
431 $string .= ' ' . $key . '="' . $value . '"';
432 }
433 } else {
434 $first = true;
435 foreach ($attributes as $key => $value) {
436 if ($entities != XML_UTIL_ENTITIES_NONE) {
437 $value = XML_Util::replaceEntities($value, $entities);
438 }
439 if ($first) {
440 $string .= ' ' . $key . '="' . $value . '"';
441 $first = false;
442 } else {
443 $string .= $linebreak . $indent . $key . '="' . $value . '"';
444 }
445 }
446 }
447 }
448 return $string;
449 }
const XML_UTIL_ENTITIES_XML
Definition Util.php:86
const XML_UTIL_CDATA_SECTION
Definition Util.php:75
const XML_UTIL_ENTITIES_NONE
Definition Util.php:80
static replaceEntities( $string, $replaceEntities=XML_UTIL_ENTITIES_XML, $encoding='ISO-8859-1')
Definition Util.php:176

References replaceEntities(), XML_UTIL_CDATA_SECTION, XML_UTIL_ENTITIES_NONE, and XML_UTIL_ENTITIES_XML.

Referenced by createStartElement(), createTagFromArray(), and getXMLDeclaration().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ collapseEmptyTags()

collapseEmptyTags ( $xml,
$mode = XML_UTIL_COLLAPSE_ALL )
static

Collapses empty tags.

Parameters
string$xmlXML
int$modeWhether to collapse all empty tags (XML_UTIL_COLLAPSE_ALL) or only XHTML (XML_UTIL_COLLAPSE_XHTML_ONLY) ones.
Returns
string XML

Definition at line 460 of file Util.php.

461 {
462 if (preg_match('~<([^>])+/>~s', $xml, $matches)) {
463 // it's already an empty tag
464 return $xml;
465 }
466 switch ($mode) {
468 $preg1 =
469 '~<' .
470 '(?:' .
471 '(https?://[^:\s]+:\w+)' . // <http://foo.com:bar ($1)
472 '|(\w+:\w+)' . // <foo:bar ($2)
473 '|(\w+)' . // <foo ($3)
474 ')+' .
475 '([^>]*)' . // attributes ($4)
476 '>' .
477 '<\/(\1|\2|\3)>' . // 1, 2, or 3 again ($5)
478 '~s'
479 ;
480 $preg2 =
481 '<' .
482 '${1}${2}${3}' . // tag (only one should have been populated)
483 '${4}' . // attributes
484 ' />'
485 ;
486 return (preg_replace($preg1, $preg2, $xml)?:$xml);
487 break;
489 return (
490 preg_replace(
491 '/<(area|base(?:font)?|br|col|frame|hr|img|input|isindex|link|meta|'
492 . 'param)([^>]*)><\/\\1>/s',
493 '<\\1\\2 />',
494 $xml
495 ) ?: $xml
496 );
497 break;
499 // fall thru
500 default:
501 return $xml;
502 }
503 }
const XML_UTIL_COLLAPSE_NONE
Definition Util.php:103
const XML_UTIL_COLLAPSE_ALL
Definition Util.php:108
const XML_UTIL_COLLAPSE_XHTML_ONLY
Definition Util.php:113

References XML_UTIL_COLLAPSE_ALL, XML_UTIL_COLLAPSE_NONE, and XML_UTIL_COLLAPSE_XHTML_ONLY.

◆ createCDataSection()

createCDataSection ( $data)
static

Create a CData section

require_once 'XML/Util.php';

// create a CData section $tag = XML_Util\createCDataSection('I am content.');

Parameters
string$datadata of the CData section
Returns
string CData section with content

Definition at line 847 of file Util.php.

848 {
849 return sprintf(
850 '<![CDATA[%s]]>',
851 preg_replace('/\‍]\‍]>/', ']]]]><![CDATA[>', strval($data))
852 );
853 }

Referenced by createTagFromArray().

Here is the caller graph for this function:

◆ createComment()

createComment ( $content)
static

Create an XML comment

require_once 'XML/Util.php';

// create an XML start element: $tag = XML_Util\createComment('I am a comment');

Parameters
string$contentcontent of the comment
Returns
string XML comment

Definition at line 827 of file Util.php.

828 {
829 $comment = sprintf('<!-- %s -->', $content);
830 return $comment;
831 }

◆ createEndElement()

createEndElement ( $qname)
static

Create an end element

require_once 'XML/Util.php';

// create an XML start element: $tag = XML_Util\createEndElement('myNs:myTag');

Parameters
string$qnamequalified tagname (including namespace)
Returns
string XML end element
See also
createStartElement(), createTag()

Definition at line 807 of file Util.php.

808 {
809 $element = sprintf('</%s>', $qname);
810 return $element;
811 }

◆ createStartElement()

createStartElement ( $qname,
$attributes = array(),
$namespaceUri = null,
$multiline = false,
$indent = '_auto',
$linebreak = "\n",
$sortAttributes = true )
static

Create a start element

require_once 'XML/Util.php';

// create an XML start element: $tag = XML_Util\createStartElement('myNs:myTag', array('foo' => 'bar') ,'http://www.w3c.org/myNs#');

Parameters
string$qnamequalified tagname (including namespace)
array$attributesarray containg attributes
string$namespaceUriURI of the namespace
bool$multilinewhether to create a multiline tag where each attribute gets written to a single line
string$indentstring used to indent attributes (_auto indents attributes so they start at the same column)
string$linebreakstring used for linebreaks
bool$sortAttributesWhether to sort the attributes or not
Returns
string XML start element
See also
createEndElement(), createTag()

Definition at line 752 of file Util.php.

756 {
757 // if no attributes hav been set, use empty attributes
758 if (!isset($attributes) || !is_array($attributes)) {
759 $attributes = array();
760 }
761
762 if ($namespaceUri != null) {
763 $parts = XML_Util::splitQualifiedName($qname);
764 }
765
766 // check for multiline attributes
767 if ($multiline === true) {
768 if ($indent === '_auto') {
769 $indent = str_repeat(' ', (strlen($qname)+2));
770 }
771 }
772
773 if ($namespaceUri != null) {
774 // is a namespace given
775 if (isset($parts['namespace']) && !empty($parts['namespace'])) {
776 $attributes['xmlns:' . $parts['namespace']] = $namespaceUri;
777 } else {
778 // define this Uri as the default namespace
779 $attributes['xmlns'] = $namespaceUri;
780 }
781 }
782
783 // create attribute list
785 $attributes, $sortAttributes,
786 $multiline, $indent, $linebreak
787 );
788 $element = sprintf('<%s%s>', $qname, $attList);
789 return $element;
790 }
static attributesToString( $attributes, $sort=true, $multiline=false, $indent=' ', $linebreak="\n", $entities=XML_UTIL_ENTITIES_XML)
Definition Util.php:392

References attributesToString(), and splitQualifiedName().

Here is the call graph for this function:

◆ createTag()

createTag ( $qname,
$attributes = array(),
$content = null,
$namespaceUri = null,
$replaceEntities = XML_UTIL_REPLACE_ENTITIES,
$multiline = false,
$indent = '_auto',
$linebreak = "\n",
$sortAttributes = true,
$collapseTagMode = XML_UTIL_COLLAPSE_ALL )
static

Create a tag

This method will call XML_Util::createTagFromArray(), which is more flexible.

require_once 'XML/Util.php';

// create an XML tag: $tag = XML_Util\createTag('myNs:myTag', array('foo' => 'bar'), 'This is inside the tag', 'http://www.w3c.org/myNs#');

Parameters
string$qnamequalified tagname (including namespace)
array$attributesarray containg attributes
mixed$contentthe content
string$namespaceUriURI of the namespace
int$replaceEntitieswhether to replace XML special chars in content, embedd it in a CData section or none of both
bool$multilinewhether to create a multiline tag where each attribute gets written to a single line
string$indentstring used to indent attributes (_auto indents attributes so they start at the same column)
string$linebreakstring used for linebreaks
bool$sortAttributesWhether to sort the attributes or not
int$collapseTagModeHow to handle a content-less, and thus collapseable, tag
Returns
string XML tag
See also
createTagFromArray() @uses createTagFromArray() to create the tag

Definition at line 541 of file Util.php.

546 {
547 $tag = array(
548 'qname' => $qname,
549 'attributes' => $attributes
550 );
551
552 // add tag content
553 if ($content !== null) {
554 $tag['content'] = $content;
555 }
556
557 // add namespace Uri
558 if ($namespaceUri !== null) {
559 $tag['namespaceUri'] = $namespaceUri;
560 }
561
563 $tag, $replaceEntities, $multiline,
564 $indent, $linebreak, $sortAttributes,
565 $collapseTagMode
566 );
567 }
static createTagFromArray( $tag, $replaceEntities=XML_UTIL_REPLACE_ENTITIES, $multiline=false, $indent='_auto', $linebreak="\n", $sortAttributes=true, $collapseTagMode=XML_UTIL_COLLAPSE_ALL)
Definition Util.php:629

References createTagFromArray(), XML_UTIL_COLLAPSE_ALL, and XML_UTIL_REPLACE_ENTITIES.

Here is the call graph for this function:

◆ createTagFromArray()

createTagFromArray ( $tag,
$replaceEntities = XML_UTIL_REPLACE_ENTITIES,
$multiline = false,
$indent = '_auto',
$linebreak = "\n",
$sortAttributes = true,
$collapseTagMode = XML_UTIL_COLLAPSE_ALL )
static

Create a tag from an array. This method awaits an array in the following format

array(
    // qualified name of the tag
    'qname' => $qname

    // namespace prefix (optional, if qname is specified or no namespace)
    'namespace' => $namespace

    // local part of the tagname (optional, if qname is specified)
    'localpart' => $localpart,

    // array containing all attributes (optional)
    'attributes' => array(),

    // tag content (optional)
    'content' => $content,

    // namespaceUri for the given namespace (optional)
    'namespaceUri' => $namespaceUri
)

require_once 'XML/Util.php';

$tag = array( 'qname' => 'foo:bar', 'namespaceUri' => 'http://foo.com', 'attributes' => array('key' => 'value', 'argh' => 'fruit&vegetable'), 'content' => 'I\'m inside the tag', ); // creating a tag with qualified name and namespaceUri $string = XML_Util\createTagFromArray($tag);

Parameters
array$tagtag definition
int$replaceEntitieswhether to replace XML special chars in content, embedd it in a CData section or none of both
bool$multilinewhether to create a multiline tag where each attribute gets written to a single line
string$indentstring used to indent attributes (_auto indents attributes so they start at the same column)
string$linebreakstring used for linebreaks
bool$sortAttributesWhether to sort the attributes or not
int$collapseTagModeHow to handle a content-less, and thus collapseable, tag
Returns
string XML tag
See also
createTag() @uses attributesToString() to serialize the attributes of the tag @uses splitQualifiedName() to get local part and namespace of a qualified name @uses createCDataSection() @uses collapseEmptyTags() @uses raiseError()

Definition at line 629 of file Util.php.

633 {
634 if (isset($tag['content']) && !is_scalar($tag['content'])) {
635 return XML_Util::raiseError(
636 'Supplied non-scalar value as tag content',
638 );
639 }
640
641 if (!isset($tag['qname']) && !isset($tag['localPart'])) {
642 return XML_Util::raiseError(
643 'You must either supply a qualified name '
644 . '(qname) or local tag name (localPart).',
646 );
647 }
648
649 // if no attributes hav been set, use empty attributes
650 if (!isset($tag['attributes']) || !is_array($tag['attributes'])) {
651 $tag['attributes'] = array();
652 }
653
654 if (isset($tag['namespaces'])) {
655 foreach ($tag['namespaces'] as $ns => $uri) {
656 $tag['attributes']['xmlns:' . $ns] = $uri;
657 }
658 }
659
660 if (!isset($tag['qname'])) {
661 // qualified name is not given
662
663 // check for namespace
664 if (isset($tag['namespace']) && !empty($tag['namespace'])) {
665 $tag['qname'] = $tag['namespace'] . ':' . $tag['localPart'];
666 } else {
667 $tag['qname'] = $tag['localPart'];
668 }
669 } elseif (isset($tag['namespaceUri']) && !isset($tag['namespace'])) {
670 // namespace URI is set, but no namespace
671
672 $parts = XML_Util::splitQualifiedName($tag['qname']);
673
674 $tag['localPart'] = $parts['localPart'];
675 if (isset($parts['namespace'])) {
676 $tag['namespace'] = $parts['namespace'];
677 }
678 }
679
680 if (isset($tag['namespaceUri']) && !empty($tag['namespaceUri'])) {
681 // is a namespace given
682 if (isset($tag['namespace']) && !empty($tag['namespace'])) {
683 $tag['attributes']['xmlns:' . $tag['namespace']]
684 = $tag['namespaceUri'];
685 } else {
686 // define this Uri as the default namespace
687 $tag['attributes']['xmlns'] = $tag['namespaceUri'];
688 }
689 }
690
691 if (!array_key_exists('content', $tag)) {
692 $tag['content'] = '';
693 }
694
695 // check for multiline attributes
696 if ($multiline === true) {
697 if ($indent === '_auto') {
698 $indent = str_repeat(' ', (strlen($tag['qname'])+2));
699 }
700 }
701
702 // create attribute list
704 $tag['attributes'],
705 $sortAttributes, $multiline, $indent, $linebreak
706 );
707
708 switch ($replaceEntities) {
710 break;
712 $tag['content'] = XML_Util::createCDataSection($tag['content']);
713 break;
714 default:
715 $tag['content'] = XML_Util::replaceEntities(
716 $tag['content'], $replaceEntities
717 );
718 break;
719 }
720 $tag = sprintf(
721 '<%s%s>%s</%s>', $tag['qname'], $attList, $tag['content'],
722 $tag['qname']
723 );
724
725 return self::collapseEmptyTags($tag, $collapseTagMode);
726 }
const XML_UTIL_ERROR_NON_SCALAR_CONTENT
Definition Util.php:60
const XML_UTIL_ERROR_NO_TAG_NAME
Definition Util.php:65
static splitQualifiedName($qname, $defaultNs=null)
Definition Util.php:877
static createCDataSection($data)
Definition Util.php:847

References attributesToString(), createCDataSection(), raiseError(), replaceEntities(), splitQualifiedName(), XML_UTIL_CDATA_SECTION, XML_UTIL_COLLAPSE_ALL, XML_UTIL_ENTITIES_NONE, XML_UTIL_ERROR_NO_TAG_NAME, XML_UTIL_ERROR_NON_SCALAR_CONTENT, and XML_UTIL_REPLACE_ENTITIES.

Referenced by createTag().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getDocTypeDeclaration()

getDocTypeDeclaration ( $root,
$uri = null,
$internalDtd = null )
static

Build a document type declaration

require_once 'XML/Util.php';

// get a doctype declaration: $xmlDecl = XML_Util\getDocTypeDeclaration('rootTag','myDocType.dtd');

Parameters
string$rootname of the root tag
string$uriuri of the doctype definition (or array with uri and public id)
string$internalDtdinternal dtd entries
Returns
string doctype declaration
Since
0.2

Definition at line 338 of file Util.php.

340 {
341 if (is_array($uri)) {
342 $ref = sprintf(' PUBLIC "%s" "%s"', $uri['id'], $uri['uri']);
343 } elseif (!empty($uri)) {
344 $ref = sprintf(' SYSTEM "%s"', $uri);
345 } else {
346 $ref = '';
347 }
348
349 if (empty($internalDtd)) {
350 return sprintf('<!DOCTYPE %s%s>', $root, $ref);
351 } else {
352 return sprintf("<!DOCTYPE %s%s [\n%s\n]>", $root, $ref, $internalDtd);
353 }
354 }

◆ getXMLDeclaration()

getXMLDeclaration ( $version = '1.0',
$encoding = null,
$standalone = null )
static

Build an xml declaration

require_once 'XML/Util.php';

// get an XML declaration: $xmlDecl = XML_Util\getXMLDeclaration('1.0', 'UTF-8', true);

Parameters
string$versionxml version
string$encodingcharacter encoding
bool$standalonedocument is standalone (or not)
Returns
string xml declaration @uses attributesToString() to serialize the attributes of the XML declaration

Definition at line 299 of file Util.php.

301 {
302 $attributes = array(
303 'version' => $version,
304 );
305 // add encoding
306 if ($encoding !== null) {
307 $attributes['encoding'] = $encoding;
308 }
309 // add standalone, if specified
310 if ($standalone !== null) {
311 $attributes['standalone'] = $standalone ? 'yes' : 'no';
312 }
313
314 return sprintf(
315 '<?xml%s?>',
316 XML_Util::attributesToString($attributes, false)
317 );
318 }

References attributesToString().

Here is the call graph for this function:

◆ isValidName()

isValidName ( $string)
static

Check, whether string is valid XML name

XML names are used for tagname, attribute names and various other, lesser known entities.

An XML name may only consist of alphanumeric characters, dashes, undescores and periods, and has to start with a letter or an underscore.

require_once 'XML/Util.php';

// verify tag name $result = XML_Util\isValidName('invalidTag?'); if (is_a($result, 'PEAR_Error')) { print 'Invalid XML name: ' . $result->getMessage(); }

Parameters
string$stringstring that should be checked
Returns
mixed true, if string is a valid XML name, PEAR error otherwise
Todo

support for other charsets

PEAR CS - unable to avoid 85-char limit on second preg_match

Definition at line 918 of file Util.php.

919 {
920 // check for invalid chars
921 if (!is_string($string) || !strlen($string) || !preg_match('/^[[:alpha:]_]\\z/', $string[0])) {
922 return XML_Util::raiseError(
923 'XML names may only start with letter or underscore',
925 );
926 }
927
928 // check for invalid chars
929 $match = preg_match(
930 '/^([[:alpha:]_]([[:alnum:]\-\.]*)?:)?'
931 . '[[:alpha:]_]([[:alnum:]\_\-\.]+)?\\z/',
932 $string
933 );
934 if (!$match) {
935 return XML_Util::raiseError(
936 'XML names may only contain alphanumeric '
937 . 'chars, period, hyphen, colon and underscores',
939 );
940 }
941 // XML name is valid
942 return true;
943 }
const XML_UTIL_ERROR_INVALID_CHARS
Definition Util.php:50
const XML_UTIL_ERROR_INVALID_START
Definition Util.php:55

References raiseError(), XML_UTIL_ERROR_INVALID_CHARS, and XML_UTIL_ERROR_INVALID_START.

Here is the call graph for this function:

◆ raiseError()

raiseError ( $msg,
$code )
static

Replacement for XML_Util\raiseError

Avoids the necessity to always require PEAR.php

Parameters
string$msgerror message
int$codeerror code
Returns
PEAR_Error
Todo
PEAR CS - should this use include_once instead?

Definition at line 957 of file Util.php.

958 {
959 include_once 'PEAR.php';
960 return PEAR::raiseError($msg, $code);
961 }

Referenced by createTagFromArray(), and isValidName().

Here is the caller graph for this function:

◆ replaceEntities()

replaceEntities ( $string,
$replaceEntities = XML_UTIL_ENTITIES_XML,
$encoding = 'ISO-8859-1' )
static

Replace XML entities

With the optional second parameter, you may select, which entities should be replaced.

require_once 'XML/Util.php';

// replace XML entites: $string = XML_Util\replaceEntities('This string contains < & >.');

With the optional third parameter, you may pass the character encoding require_once 'XML/Util.php';

// replace XML entites in UTF-8: $string = XML_Util\replaceEntities( 'This string contains < & > as well as ä, ö, ß, à and ê', XML_UTIL_ENTITIES_HTML, 'UTF-8' );

Parameters
string$stringstring where XML special chars should be replaced
int$replaceEntitiessetting for entities in attribute values (one of XML_UTIL_ENTITIES_XML, XML_UTIL_ENTITIES_XML_REQUIRED, XML_UTIL_ENTITIES_HTML)
string$encodingencoding value (if any)... must be a valid encoding as determined by the htmlentities() function
Returns
string string with replaced chars
See also
reverseEntities()

Definition at line 176 of file Util.php.

178 {
179 switch ($replaceEntities) {
181 return strtr(
182 $string,
183 array(
184 '&' => '&amp;',
185 '>' => '&gt;',
186 '<' => '&lt;',
187 '"' => '&quot;',
188 '\'' => '&apos;'
189 )
190 );
191 break;
193 return strtr(
194 $string,
195 array(
196 '&' => '&amp;',
197 '<' => '&lt;',
198 '"' => '&quot;'
199 )
200 );
201 break;
203 return htmlentities($string, ENT_COMPAT, $encoding);
204 break;
205 }
206 return $string;
207 }
const XML_UTIL_ENTITIES_HTML
Definition Util.php:98
const XML_UTIL_ENTITIES_XML_REQUIRED
Definition Util.php:92

References XML_UTIL_ENTITIES_HTML, XML_UTIL_ENTITIES_XML, and XML_UTIL_ENTITIES_XML_REQUIRED.

Referenced by attributesToString(), and createTagFromArray().

Here is the caller graph for this function:

◆ reverseEntities()

reverseEntities ( $string,
$replaceEntities = XML_UTIL_ENTITIES_XML,
$encoding = 'ISO-8859-1' )
static

Reverse XML entities

With the optional second parameter, you may select, which entities should be reversed.

require_once 'XML/Util.php';

// reverse XML entites: $string = XML_Util\reverseEntities('This string contains < & >.');

With the optional third parameter, you may pass the character encoding require_once 'XML/Util.php';

// reverse XML entites in UTF-8: $string = XML_Util\reverseEntities( 'This string contains < & > as well as' . ' ä, ö, ß, à and ê', XML_UTIL_ENTITIES_HTML, 'UTF-8' );

Parameters
string$stringstring where XML special chars should be replaced
int$replaceEntitiessetting for entities in attribute values (one of XML_UTIL_ENTITIES_XML, XML_UTIL_ENTITIES_XML_REQUIRED, XML_UTIL_ENTITIES_HTML)
string$encodingencoding value (if any)... must be a valid encoding as determined by the html_entity_decode() function
Returns
string string with replaced chars
See also
replaceEntities()

Definition at line 248 of file Util.php.

250 {
251 switch ($replaceEntities) {
253 return strtr(
254 $string,
255 array(
256 '&amp;' => '&',
257 '&gt;' => '>',
258 '&lt;' => '<',
259 '&quot;' => '"',
260 '&apos;' => '\''
261 )
262 );
263 break;
265 return strtr(
266 $string,
267 array(
268 '&amp;' => '&',
269 '&lt;' => '<',
270 '&quot;' => '"'
271 )
272 );
273 break;
275 return html_entity_decode($string, ENT_COMPAT, $encoding);
276 break;
277 }
278 return $string;
279 }

References XML_UTIL_ENTITIES_HTML, XML_UTIL_ENTITIES_XML, and XML_UTIL_ENTITIES_XML_REQUIRED.

◆ splitQualifiedName()

splitQualifiedName ( $qname,
$defaultNs = null )
static

Split qualified name and return namespace and local part

require_once 'XML/Util.php';

// split qualified tag $parts = XML_Util\splitQualifiedName('xslt:stylesheet'); the returned array will contain two elements:

array(
    'namespace' => 'xslt',
    'localPart' => 'stylesheet'
);
Parameters
string$qnamequalified tag name
string$defaultNsdefault namespace (optional)
Returns
array array containing namespace and local part

Definition at line 877 of file Util.php.

878 {
879 if (strstr($qname, ':')) {
880 $tmp = explode(':', $qname);
881 return array(
882 'namespace' => $tmp[0],
883 'localPart' => $tmp[1]
884 );
885 }
886 return array(
887 'namespace' => $defaultNs,
888 'localPart' => $qname
889 );
890 }

Referenced by createStartElement(), and createTagFromArray().

Here is the caller graph for this function:

The documentation for this class was generated from the following file:
  • E:/Bearsampp-development/sandbox/core/libs/php/pear/pear/XML/Util.php