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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: sbergmann@php.net
New email:
PHP Version: OS:

 

 [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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Tue May 06 17:02:17 2025 UTC