spaces in text ---> html

Discussion in 'Perl' started by Peter Smith, Dec 19, 2003.

  1. Peter Smith

    Peter Smith Guest

    Hi

    I am writing a message board, and the text is entered in a text box and
    outputted in HTML. How can I keep the spaces formatting (ie use  's)
    in the html output??

    I use the standard decode lines:


    $value =~ tr/+/ /;

    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;


    but when I use

    $value =~ tr/+/"\&nbsp\;"/;

    I get repeated &'s instead of spaces. Any help much appreciated..

    - Peter
    Peter Smith, Dec 19, 2003
    #1
    1. Advertising

  2. tr// is a one-to-one transformation, meaning there (should be) the
    same # of characters in each operand. Thus, the line:

    $value =~ tr/+/"\&nbsp\;"/

    will be interpreted as "translate a + sign to a quote, then
    translate... oops, all done!" since there's only the plus sign on the
    left.

    Try:

    $value =~ s/\+/\&nbsp\;/g;

    to get the desired effect. Note the \+ in the construct above.

    MAC


    "Peter Smith" <> wrote in message news:<awzEb.58200$>...
    > Hi
    >
    > I am writing a message board, and the text is entered in a text box and
    > outputted in HTML. How can I keep the spaces formatting (ie use &nbsp;'s)
    > in the html output??
    >
    > I use the standard decode lines:
    >
    >
    > $value =~ tr/+/ /;
    >
    > $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
    >
    >
    > but when I use
    >
    > $value =~ tr/+/"\&nbsp\;"/;
    >
    > I get repeated &'s instead of spaces. Any help much appreciated..
    >
    > - Peter
    Michael Capone, Dec 19, 2003
    #2
    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. John B. Matthews
    Replies:
    4
    Views:
    655
    John B. Matthews
    Sep 12, 2008
  2. Roedy Green
    Replies:
    3
    Views:
    613
  3. Tomasz Chmielewski

    [CSS] how can I show spaces as spaces?

    Tomasz Chmielewski, Sep 5, 2009, in forum: HTML
    Replies:
    21
    Views:
    1,571
    Jan C. Faerber
    Sep 10, 2009
  4. Tomasz Chmielewski

    how can I show spaces as spaces, part 2

    Tomasz Chmielewski, Sep 9, 2009, in forum: HTML
    Replies:
    14
    Views:
    862
    Jan C. Faerber
    Sep 10, 2009
  5. johkar
    Replies:
    2
    Views:
    2,849
    Mayeul
    Dec 10, 2009
Loading...

Share This Page