[PHP] Invalid Characters, XML...

Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default RE: [PHP] Invalid Characters, XML...

    Here's what I have been using.


    $trans= array("'" => "&#39;", "'" => "&#39;",">" => "&#62;", "<" => "&#60;",
    "&" => "&#38;","-" => "&#45;", "°" => "&#176;", "±" => "&#177;", "-" =>
    "–", """ => "“", """ => "”","..." => "…","'" =>
    "‘","²" =>"&#178;","·" => "&#183;" );

    $value=strtr($value,$trans);



    Luis
    -----Original Message-----
    From: David Otton [mailto:phpmail@jawbone.freeserve.co.uk]
    Sent: Monday, August 04, 2003 7:18 AM
    To: Russell P Jones
    Cc: [email]php-general@lists.php.net[/email]
    Subject: Re: [PHP] Invalid Characters, XML...


    On Sun, 3 Aug 2003 21:51:53 -0400 (EDT), you wrote:
    >Im using PHP to write to XML files, but I am having some problems. A lot
    >of users are cutting and pasting content from text editors like word,
    >which uses odd quotation marks, dashes, etc. which PHP writes to the XML
    >file, and then the XML parser does not under stand. Is there a
    >stripslashes() or htmlspecialchars() equivalent that will convert this
    >kind of stuff to the correct ascii text?
    This should get you started. It behaves as does htmlentities().

    For those high-ASCII characters out of Word/IE... decide what regular ASCII
    character you want to map them to, (eg slanted-quote-open and -close to
    regular quote), and add them to the $trans array before performing the
    array_walk().

    function xmlentities ($string, $quote_style = ENT_COMPAT)
    {
    static $trans;
    if (!is_array ($trans)) {
    $trans = get_html_translation_table (HTML_ENTITIES, $quote_style);
    array_walk ($trans, create_function ('&$a, $b', '$a = "&#" . ord ($b) .
    ";";'));
    }
    return (strtr ($string, $trans));
    }



    --
    PHP General Mailing List (http://www.php.net/)
    To unsubscribe, visit: http://www.php.net/unsub.php

    Luis Lebron Guest

  2. Similar Questions and Discussions

    1. error invalid characters in my cfquery?
      The list. What is that datatype your passing the list to? Is it an numeric based or string? If it is a string (char, varchar, ntext, nvarchar,...
    2. Using Invalid Characters
      I am using MS SQL for my ASP application and have several 'comments' fields. Obviously in these fields users are going to enter invalid characters...
    3. Matching invalid characters in a URL
      I'm trying to throw out URLs with any invalid characters in them, like '@". According to http://www.ietf.org/rfc/rfc1738.txt : Thus, only...
    4. #25405 [Opn->Bgs]: The session id contains invalid characters
      ID: 25405 Updated by: iliaa@php.net Reported By: pop501 at hotmail dot com -Status: Open +Status: ...
    5. Invalid Characters, XML...
      Im using PHP to write to XML files, but I am having some problems. A lot of users are cutting and pasting content from text editors like word,...
  3. #2

    Default RE: [PHP] Invalid Characters, XML...

    I had a similar problem recently, but was not able to work with it in PHP
    tho. The array for that mapped characters to their entity turned out to be
    HUGE and it took forever to evaluate long XML files.

    I ended up killing several birds with one stone by wrapping the html-tidy
    utility (tidy.sourceforge.net) in php. It validates xml, converts all
    characters >127 into their respective entity, pretties up the XML output,
    cleans up Word 2000 specific content and deals with a variety of
    input/output encodings. It did all these a lot faster that any of the
    scripts I had written and saved me from writing others.

    -----Original Message-----
    From: Russell P Jones [mailto:rjones@email.unc.edu]
    Sent: Sunday, August 03, 2003 6:52 PM
    To: [email]php-general@lists.php.net[/email]
    Subject: [PHP] Invalid Characters, XML...


    Im using PHP to write to XML files, but I am having some problems. A lot of
    users are cutting and pasting content from text editors like word, which
    uses odd quotation marks, dashes, etc. which PHP writes to the XML file, and
    then the XML parser does not under stand. Is there a
    stripslashes() or htmlspecialchars() equivalent that will convert this kind
    of stuff to the correct ascii text?

    Russ


    --
    PHP General Mailing List (http://www.php.net/)
    To unsubscribe, visit: http://www.php.net/unsub.php
    Ivo Pletikosic Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139