escape character

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dragon52
    New Member
    • Jun 2009
    • 72

    escape character

    Hi all,

    When sending an email I have the following in the body text.

    $body = ".... school's address ....";

    the ".school's. " part in the text ends up looking like ".school!~s ." when the email is sent.

    Can anyone tell me what the escape sequence is so the apostrophe char is display correctly?

    thanks
    Denis
  • anfetienne
    Contributor
    • Feb 2009
    • 424

    #2
    try this...i had a similar problem earlier

    $body = ".... school's address ....";
    $body= mysql_real_esca pe_string($body );

    Comment

    • Dormilich
      Recognized Expert Expert
      • Aug 2008
      • 8694

      #3
      you could try the typographical apostrophe… (’)

      Comment

      • Atli
        Recognized Expert Expert
        • Nov 2006
        • 5062

        #4
        Hi.

        Did you try simply:
        [code=php]$str = "John\'s name.";[/code]

        Is it a HTML email?
        Then try:
        [code=html]$str = "John&# 39;s name.";[/code]
        Last edited by Atli; Jun 8 '09, 09:59 PM. Reason: Added the HTML bit.

        Comment

        • prabirchoudhury
          New Member
          • May 2009
          • 162

          #5
          escape character

          hey

          you could have to place "\" before the single quotes inside the $body = " \ before any single quote";

          2. check the $body before you send it with calling str_replace();


          Code:
          // place "\" before single quotes.
          $changeto   = array("\'");
          $body = str_replace(chr(145), changeto , $body );
          $body = str_replace(chr(146), changeto, $body );
          $body = str_replace(chr(39), changeto, $body );
          :)

          Comment

          • Atli
            Recognized Expert Expert
            • Nov 2006
            • 5062

            #6
            Originally posted by prabirchoudhury
            hey

            you could have to place "\" before the single quotes inside the $body = " \ before any single quote";

            2. check the $body before you send it with calling str_replace();


            Code:
            // place "\" before single quotes.
            $changeto   = array("\'");
            $body = str_replace(chr(145), changeto , $body );
            $body = str_replace(chr(146), changeto, $body );
            $body = str_replace(chr(39), changeto, $body );
            :)
            Best to do that manually, or you risk double-slashing quotes.

            And there is always the addslashes function ;)

            Comment

            • prabirchoudhury
              New Member
              • May 2009
              • 162

              #7
              ya that’s true it has some problem with mysql injection and other replacement but would be alright for html and it is hard to put anything instead single quote manually all the time. might be better to do something with program instead of manual... i am not very much expert, still learning :)

              Comment

              • Atli
                Recognized Expert Expert
                • Nov 2006
                • 5062

                #8
                I don't expect many applications would require you to manually enter a lot of text like that. Most of them would take user input and use that, which should already be in the proper format. (After sanitation, of course.)

                For what little you may have to enter manually, you should be able to suffer through whatever manual escaping is required :)

                Comment

                • dragon52
                  New Member
                  • Jun 2009
                  • 72

                  #9
                  Thanks everyone for your input.

                  I have tried mysql_real_esca pe_string() and it works. But I can't use it because I have other special chars in the text I need to keep such "\n" for line breaks.

                  I have decided to use " school`s " instead, the back apostrophe thingie.

                  Thanks all the same.

                  Denis

                  Comment

                  Working...