Results 1 to 4 of 4

Thread: str_replace to find and fix weird quotes

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2005
    Posts
    431

    str_replace to find and fix weird quotes

    How would I go about replacing weird quotes?

    ex: ‘,’, “, and ”.

    Code:
    $vCLEANED = str_replace("'", "\'", $vSlashes);
    	$vCLEANED = str_replace('"', '\"', $vCLEANED);
    	$vCLEANED = str_replace("’", "\'", $vCLEANED);
    First two lines work, third one does not.

    These are apparently latin extended A and B
    http://www.ascii.cl/htmlcodes.htm (bottom)

  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: str_replace to find and fix weird quotes

    Have a look at addslashes(); http://uk.php.net/add_slashes

    If this data is going in a database though I suggest you use an abstraction layer such as Pear::MDB or PDO as they will automatically handle the escaping of data for you.


    [Fixed errant smiley — Mod]
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    May 2005
    Posts
    431

    Re: str_replace to find and fix weird quotes

    Quote Originally Posted by visualAd
    Have a look at addslashes(); http://uk.php.net/add_slashes

    If this data is going in a database though I suggest you use an abstraction layer such as Pear::MDB or PDO as they will automatically handle the escaping of data for you.


    [Fixed errant smiley — Mod]
    add_slashes gives me the same issue.

    I need some voodoo which lets me detect them so I can replace them with a real '.

    The DB is a mysql, and its for a internal intranet site were securty is not very high.

    edit: and
    Code:
    $vCLEANED = str_replace(chr(402), "\'", $vCLEANED);
    also does not work.

    edit2: and to top of all the fun... I had two scripts. One of them was working, the other was not. Then I merged them (but without really touching the first) and now they both dont work....
    Last edited by Zeratulsdomain; Feb 15th, 2008 at 10:03 AM.

  4. #4
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: str_replace to find and fix weird quotes

    I understand what you are saying now. You need to find the character code when it reaches your script as a different character encoding on the client side can yeild different results on the server side.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width