6
4

5 回答 5

3
$stdin = mb_str_replace('’', '\'', $stdin);

Implementation of mb_str_replace() here: http://www.php.net/manual/en/ref.mbstring.php#107631

I mean this:

<?php
function mb_str_replace($needle, $replacement, $haystack) {
   return implode($replacement, mb_split($needle, $haystack));
}
echo mb_str_replace('’', "'", "String’s Title");

It may solve encoding problems.

于 2012-07-05T18:39:27.633 回答
1

Try this

$s = "String’s Title";
$h = str_replace("’","'",$s);
echo $h;

Also can Try with preg_replace

echo preg_replace('/\’/',"'","String’s Title");
于 2012-07-05T18:42:04.340 回答
1

I have just tested this:

echo str_replace('&#8217;', "'", $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.

于 2012-07-05T18:42:45.473 回答
0

I don't know why str_replace() is not working for you.

I feel you haven't tried it in correct way.

Refer LIVE DEMO

<?php
    $str = "String’s Title";
    echo str_replace('’', '\'', $str) . "\n";
    echo str_replace("’", "'", $str);
?>

OUTPUT:

String's Title
String's Title

UPDATE 1:

You may need to try setting the header as

header('Content-Type: text/html; charset=utf-8');
于 2012-07-05T18:49:55.143 回答
0

I came across a similar issue trying to replace apostrophes with underscores... I ended up having to write this (and this was for a WordPress site):

$replace = array(",","'","’"," ","&#8217;","&#8211;");
$downloadTitle = str_replace( $replace,"_",get_the_title($gallery_id));

I'm new to PHP myself, and realize this is pretty hideous code, but it worked for me. I realized it was the "’" that REALLY needed to be factored in for some reason.

于 2014-09-12T04:47:58.843 回答