How to convert ascii to text

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • veg_all@yahoo.com

    How to convert ascii to text

    I replace some user input with their ascii equivalent so they display
    on the webpage properly:

    $entry = preg_replace ( "/\'+/" , '&#39' , $entry);
    $entry = preg_replace ( "/\,+/" , '&#44' , $entry);

    I then need to email the data, however in email the ascii code is
    displayed, not the text.
    Is there an easier way to convert the ascii back to the text without
    another preg_replace?

  • pangea33

    #2
    Re: How to convert ascii to text

    veg_all@yahoo.c om wrote:
    I replace some user input with their ascii equivalent so they display
    on the webpage properly:
    >
    $entry = preg_replace ( "/\'+/" , '&#39' , $entry);
    $entry = preg_replace ( "/\,+/" , '&#44' , $entry);
    >
    I then need to email the data, however in email the ascii code is
    displayed, not the text.
    Is there an easier way to convert the ascii back to the text without
    another preg_replace?
    There really doesn't seem to be any reason you have to manually escape
    the string with a regular expression, then change it back. Especially
    since you're only accounting for a small set of characters that might
    have problems. Why not leave the variable exactly as entered by the
    user, and just run it through the "htmlspecialcha rs()" function when
    you want to display it on the page?



    Comment

    • Tim Roberts

      #3
      Re: How to convert ascii to text

      veg_all@yahoo.c om wrote:
      >
      >I replace some user input with their ascii equivalent so they display
      >on the webpage properly:
      >
      >$entry = preg_replace ( "/\'+/" , '&#39' , $entry);
      >$entry = preg_replace ( "/\,+/" , '&#44' , $entry);
      Are you aware that this will replace a string of quotes ('''''') or commas
      (,,,,,,,) with a single &#39 or &#44? I'm pretty sure you don't want the
      plus signs in there.

      I assume this wasn't cut-and-pasted from your code, because the entities
      must have trailing semicolons: '

      Also, there is no reason to quote a comma. What led you to do that?
      --
      Tim Roberts, timr@probo.com
      Providenza & Boekelheide, Inc.

      Comment

      Working...