Replacing all "special characters" with code

Discussion in 'Perl Misc' started by Mike, Feb 19, 2004.

  1. Mike

    Mike Guest

    I'm currently changing all of my "special characters," like &, ",
    whitespace, etc to their HTML counterparts manually (& "
    $nbsp;). The problem is, there could be several that I'm forgetting.

    Is there a faster way to transfer all of these characters at once?

    On a similar note, any thoughts on a good replacement for a single
    quote? I'm using ´, but it's not quite the same.

    TIA,

    Mike
    Mike, Feb 19, 2004
    #1
    1. Advertising

  2. Mike

    Ben Morrow Guest

    (Mike) wrote:
    > I'm currently changing all of my "special characters," like &, ",
    > whitespace, etc to their HTML counterparts manually (& "
    > $nbsp;). The problem is, there could be several that I'm forgetting.
    >
    > Is there a faster way to transfer all of these characters at once?


    I usually use
    s/&/&/g;
    s/"/"/g;
    s/</&lt;/;
    s/>/&gt;/;
    s/([^[:ascii:]])/sprintf '&#x%04X;' ord $1/ge;

    > On a similar note, any thoughts on a good replacement for a single
    > quote? I'm using &acute;, but it's not quite the same.


    Err, no, they're completely different. The correct replacement is
    &apos;, but replacement is not necessary and IIRC some versions of IE
    don't correctly recognize it.

    Ben

    --
    And if you wanna make sense / Whatcha looking at me for? (Fiona Apple)
    * *
    Ben Morrow, Feb 19, 2004
    #2
    1. Advertising

  3. Mike

    Tore Aursand Guest

    On Wed, 18 Feb 2004 19:32:06 -0800, Mike wrote:
    > I'm currently changing all of my "special characters," like &, ",
    > whitespace, etc to their HTML counterparts manually (&amp; &quot;
    > $nbsp;). The problem is, there could be several that I'm forgetting. Is
    > there a faster way to transfer all of these characters at once?


    Take a look at HTML::Entities. Maybe not faster, but at least you get to
    have all the characters encoded correctly.


    --
    Tore Aursand <>
    "The purpose of all war is ultimately peace." -- Saint Augustine
    Tore Aursand, Feb 19, 2004
    #3
  4. On 18 Feb 2004 19:32:06 -0800, (Mike) wrote:

    >I'm currently changing all of my "special characters," like &, ",
    >whitespace, etc to their HTML counterparts manually (&amp; &quot;
    >$nbsp;). The problem is, there could be several that I'm forgetting.


    Even if it does just the opposite transformation, you may be
    interested in giving a peek into Tom Christiansen script mentioned at
    'perldoc -q HTML'!


    Michele
    --
    you'll see that it shouldn't be so. AND, the writting as usuall is
    fantastic incompetent. To illustrate, i quote:
    - Xah Lee trolling on clpmisc,
    "perl bug File::Basename and Perl's nature"
    Michele Dondi, Feb 19, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stefan Mueller
    Replies:
    3
    Views:
    32,988
    Stefan Mueller
    Jul 23, 2006
  2. Replies:
    2
    Views:
    1,084
    Ingo Menger
    May 31, 2007
  3. rvino
    Replies:
    0
    Views:
    4,649
    rvino
    Aug 14, 2007
  4. david.karr
    Replies:
    3
    Views:
    136
    david.karr
    Jun 6, 2006
  5. majna
    Replies:
    4
    Views:
    656
    Thomas 'PointedEars' Lahn
    Sep 19, 2007
Loading...

Share This Page