php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #12447 Function to encode strings for XML
Submitted: 2001-07-28 06:38 UTC Modified: 2002-11-30 09:20 UTC
From: sbergmann@php.net Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: 4.0.6 OS:
Private report: No CVE-ID: None
 [2001-07-28 06:38 UTC] sbergmann@php.net
Currently I use

function &xml_encode(&$xml) {
  $xml = str_replace(array('?', '?', '?',
                           '?', '?', '?',
                           '?'
                          ),
                     array('ü', 'Ü', 'ö',
                           'Ö', 'ä', 'Ä',
                           'ß'
                          ),
                     $xml
                    );

  $xml = preg_replace(array("/\&([a-z\d\#]+)\;/i",
                            "/\&/",
                            "/\#\|\|([a-z\d\#]+)\|\|\#/i",
                            "/([^a-zA-Z\d\s\<\>\&\;\.\:\=\"\-\/\%\?\!\'\(\)\[\]\{\}\$\#\+\,\@_])/e"
                           ),
                      array("#||\\1||#",
                            "&amp;",
                            "&\\1;",
                            "'&#'.ord('\\1').';'"
                           ),
                      $xml
                     );

  return $xml;
} 

to 'encode' strings for use with XML. A 'PHP Land' implementation of this would be handy, I think.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-11-30 09:20 UTC] chregu@php.net
ext/recode has an XML mode. Maybe that helps (not sure about windows, though)

chregu
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 13:01:28 2024 UTC