www.webdeveloper.com
Results 1 to 8 of 8

Thread: str_replace apostrophes

  1. #1
    Join Date
    Feb 2006
    Location
    Toronto
    Posts
    105

    str_replace apostrophes

    this is what i've got: str_replace("&#39","'",'<br />',$_POST["solution"])
    i need it to allow "'" and replace line breaks with "<br />"

    thank you!

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,245
    PHP Code:
    $search = array('&#39;''<br />');
    $replace = array("'""\n");
    $newString str_replace($search$replace$oldString); 
    Last edited by NogDog; 11-09-2006 at 05:28 PM.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Jan 2005
    Location
    Alicante (Spain)
    Posts
    7,739
    Quote Originally Posted by NogDog
    PHP Code:
    $search = array('&#39;''<br />');
    $replace = array("'""\n");
    $newString str_replace($search$replace$oldString); 
    Something strange happened with the quotes.
    Last edited by bokeh; 11-09-2006 at 05:10 PM.

  4. #4
    Join Date
    Apr 2003
    Location
    Rosemount, MN
    Posts
    2,287
    Quote Originally Posted by NogDog
    PHP Code:
    $search = array(''', '<br />');
    $replace = array("'", "
    \n");
    $newString = str_replace($search$replace$oldString); 
    don't you need to escapestring?

    Like this:
    PHP Code:
    $search = array('\'''<br />');
    $replace = array("'""\n");
    $newString str_replace($search$replace$oldString); 
    My settings

    Browser :: FireFox 1.5
    Resolution :: 1152x864
    Connection :: Cable Modem 2Mbs

  5. #5
    Join Date
    Jan 2005
    Location
    Alicante (Spain)
    Posts
    7,739

  6. #6
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,245
    Thanks, fixed it by using the numeric character entity for "&" followed by "#39;".
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  7. #7
    Join Date
    Feb 2006
    Location
    Toronto
    Posts
    105
    argh... it doesn't appear to be working... or at least, when i the entry is updated into the database, it throws this error (where "test as's" is what i entered to see if it was working):

    test as'sYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 's', '2006-11-16 01:11:44')' at line 13test as'sYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 's', '2006-11-16 01:11:44')' at line 13

  8. #8
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,245
    You'll need to escape any quotes before using the value in a query. If using mysql, use the mysql_real_escape_string() function, otherwise use addslashes().
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles