note 89970 added to domxpath.registernamespace

From: Date: Tue, 31 Mar 2009 12:55:58 +0000
Subject: note 89970 added to domxpath.registernamespace
Groups: php.notes 
Request: Send a blank email to php-notes+get-152648@lists.php.net to get a copy of this message
Ok, here's a function that extends XPath syntax with the following special characters: ~ inserts default namespace prefix if defined # shorthand for text() % shorthand for comment() $ shorthand for node() ?* shorthand for processing-instruction() ?foo shorthand for processing-instruction("foo") ? shorthand for processing-instruction("") ^ escapes following character (with literal or SGML entity as needed) All of the above except ^ are ignored within quoted strings <?php function extendXPath($str, $defns = NULL) { $quote = false; $map = array( '~' => isset($defns) ? "$defns:" : '', '#' => 'text()', '%' => 'comment()', '$' => 'node()' ); $out = ''; for ($i = 0, $len = strlen($str); $i < $len; $i++) { $c = $str[$i]; if (!$quote && array_key_exists($c, $map)) { $out .= $map[$c]; } else switch ($c) { case '^': $out .= htmlspecialchars($str[++$i], ENT_QUOTES); break; case '?': if ($quote) { $out .= $c; } elseif ($str[$i + 1] == '*') { $out .= 'processing-instruction()'; $i++; } else { preg_match('/^\w+/', substr($str, $i + 1), $matches); $out .= 'processing-instruction("'.$matches[0].'")'; $i += strlen($matches[0]); }; break; case '"': $quote = !$quote; default: $out .= $c; }; }; return $out; } ?> ---- Server IP: 89.31.146.176 Probable Submitter: 82.247.193.104 ---- Manual Page -- http://www.php.net/manual/en/domxpath.registernamespace.php Edit -- https://master.php.net/note/edit/89970 Del: integrated -- https://master.php.net/note/delete/89970/integrated Del: useless -- https://master.php.net/note/delete/89970/useless Del: bad code -- https://master.php.net/note/delete/89970/bad+code Del: spam -- https://master.php.net/note/delete/89970/spam Del: non-english -- https://master.php.net/note/delete/89970/non-english Del: in docs -- https://master.php.net/note/delete/89970/in+docs Del: other reasons-- https://master.php.net/note/delete/89970 Reject -- https://master.php.net/note/reject/89970 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#152648) next »