escape charecters

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Desmond

    #1

    escape charecters

    Can anyone tell me ho to get certain charecters to be displayed.
    When sending email with (') i get (\) instead. i.e.

    This dosen't work becomes dosen\t

    Is there some kind of escape key to get passed this please.

  • Ken Robinson

    #2
    Re: escape charecters

    Desmond wrote:[color=blue]
    > Can anyone tell me ho to get certain charecters to be displayed.
    > When sending email with (') i get (\) instead. i.e.
    >
    > This dosen't work becomes dosen\t
    >
    > Is there some kind of escape key to get passed this please.[/color]

    How are the stings you're sending getting set. If the information is
    coming from a form, you should use the function stripslashes() on the
    input before sending.

    If you are creating the strings yourself, you can surround strings
    containing single quotes with double quotes and vice versa.

    Example:

    $str1 = "this string contains a single quote ' ";
    $str2 = 'This string contains a double quote " ';
    echo $str1.'<br>'.$s tr2."<br>\n";

    Ken

    Comment

    • Desmond

      #3
      Re: escape charecters

      Wha I am doing is using a html form for sending an Email the input box
      may have a name
      Paul O'Brien so the PHP line $name = $_POST["Name"]; end up in the
      email as
      Paul O\Brien replacing the the (') to (\) if i use stripslashes()
      there are no slashes to strip

      do i need a search and replace string.

      Desmond.

      Comment

      • Desmond

        #4
        Re: escape charecters

        Sorted. I don't know why this is happening but if I enter

        Paul O'Brian in a html page and submit this to a PHP page it adds a (\)
        giving me Paul O\'Brian

        I have to use the following $name = str_replace("\\ " ,"" , $name);
        to correct it.

        Why ?

        Desmond.

        Comment

        • Ken Robinson

          #5
          Re: escape charecters

          Desmond wrote:[color=blue]
          > Wha I am doing is using a html form for sending an Email the input box
          > may have a name
          > Paul O'Brien so the PHP line $name = $_POST["Name"]; end up in the
          > email as
          > Paul O\Brien replacing the the (') to (\) if i use stripslashes()
          > there are no slashes to strip[/color]

          Here's a sample program I just wrote:

          <?
          if (isset($_POST['submit'])) {
          echo '$_POST array<pre>';
          print_r($_POST) ;
          echo '</pre>';
          $name = stripslashes($_ POST['name']);
          echo 'You entered the name of <span style="font-weight:bold">' . $name
          .. "</span><br>\n";
          }

          ?>
          <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
          "http://www.w3.org/TR/html4/strict.dtd">

          <html>
          <head>
          <title>Test form</title>
          </head>

          <body>
          <form method="post" action="<? echo $_SERVER['PHP_SELF']?>">
          Name: <input type="text" style="width:50 %" name="name"><br >
          <input type="submit" name="submit" value="Send Data">
          </form>


          </body>
          </html>

          And here's the output:

          $_POST array

          Array
          (
          [name] => O\'Brian
          [submit] => Send Data
          )

          You entered the name of O'Brian

          Notice how the single quote is escaped in the input data, so when I
          assign it to a variable I used stripslashes() to unescape it.

          Compare this code to what you have (since you didn't post it) and see
          if it differs. Then run this code to see what it produces.

          Ken

          Comment

          • Ken Robinson

            #6
            Re: escape charecters



            Desmond wrote:[color=blue]
            > Sorted. I don't know why this is happening but if I enter
            >
            > Paul O'Brian in a html page and submit this to a PHP page it adds a (\)
            > giving me Paul O\'Brian
            >
            > I have to use the following $name = str_replace("\\ " ,"" , $name);
            > to correct it.[/color]

            That's because "Magic Quotes" are turned on. As I said before, use the
            function stripslashes() to remove the escape character.

            Ken

            Comment

            Working...