Search code examples
phpstr-replaceapostrophe

Replace " ’ " with " ' " in PHP


I'm grabbing a string from the database that could be something like String’s Title however I need to replace the with a ' so that I can pass the string to an external API. I've used just about every variation of escaped strings in str_replace() that I can think of to no avail.


Solution

  • I have just tested this:

    echo str_replace('’', "'", $cardnametitle);
    //Outputs: String's Title
    

    Edit: I believe that entries in your database have been htmlentitiesed.

    Note: I'm pretty sure this is not a good solution, even though it did solve your problem I think there should be a better way to do it.