home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 June / ENTER.ISO / files / xampp-win32-1.4.5-installer.exe / xampp / 005.phpt < prev    next >
Encoding:
Text File  |  2004-03-24  |  1.9 KB  |  76 lines

  1. --TEST--
  2. XML Parser: mixing character encodings
  3. --SKIPIF--
  4. <?php if (!extension_loaded("xml")) echo 'skip'; ?>
  5. --FILE--
  6. <?php // -*- C++ -*-
  7. //
  8. // Test for: XML/Parser.php
  9. // Parts tested: - mixing character encodings
  10. //
  11. // This is what we test:
  12. // 1 UTF-8      -> ISO-8859-1
  13. // 2 UTF-8      -> US-ASCII
  14. // 3 ISO-8859-1 -> UTF-8
  15. // 4 ISO-8859-1 -> US-ASCII
  16. // 5 US-ASCII   -> UTF-8
  17. // 6 US-ASCII   -> ISO-8859-1
  18. //
  19.  
  20. require_once "XML/Parser.php";
  21.  
  22. class TestEncodings1 extends XML_Parser {
  23.     var $output = '';
  24.  
  25.     function TestEncodings1($to, $from) {
  26.         $this->XML_Parser($from, 'event', $to);
  27.     }
  28.     function startHandler($xp, $elem, $attribs) {
  29.         $this->output .= "<$elem>";
  30.     }
  31.     function endHandler($xp, $elem) {
  32.         $this->output .= "</$elem>";
  33.     }
  34.     function cdataHandler($xp, $data) {
  35.         $this->output .= $data;
  36.     }
  37.     function test($data) {
  38.         // $this->output = '';
  39.         $this->parseString($data, true);
  40.         return $this->output;
  41.     }
  42. }
  43.  
  44. $xml = "<?xml version='1.0' ?>";
  45. $input = array(
  46.     "UTF-8"      => "<a>abc├ª├╕├Ñ</a>",
  47.     "ISO-8859-1" => "<a>abcµ°σ</a>",
  48.     "US-ASCII"   => "<a>abcaoa</a>"
  49. );
  50.  
  51. $encodings = array_keys($input);
  52. foreach ($input as $srcenc => $string) {
  53.     foreach ($encodings as $tgtenc) {
  54.         if ($srcenc == $tgtenc) {
  55.             continue;
  56.         }
  57.         print "Testing $srcenc -> $tgtenc: ";
  58.         $p =& new TestEncodings1($tgtenc, $srcenc);
  59.         $e = $p->test($input[$srcenc]);
  60.         if (PEAR::isError($e)) {
  61.             printf("OOPS: %s\n", $e->getMessage());
  62.         } else {
  63.             var_dump($e);
  64.         }
  65.     }
  66. }
  67.  
  68. ?>
  69. --EXPECT--
  70. Testing UTF-8 -> ISO-8859-1: string(13) "<A>abcµ°σ</A>"
  71. Testing UTF-8 -> US-ASCII: string(13) "<A>abc???</A>"
  72. Testing ISO-8859-1 -> UTF-8: string(16) "<A>abc├ª├╕├Ñ</A>"
  73. Testing ISO-8859-1 -> US-ASCII: string(13) "<A>abc???</A>"
  74. Testing US-ASCII -> UTF-8: string(13) "<A>abcaoa</A>"
  75. Testing US-ASCII -> ISO-8859-1: string(13) "<A>abcaoa</A>"
  76.