Jump to content

Str_replace, Problem With "'" Character


son
 Share

Recommended Posts

Receiving advice in this forum about differences in between preg_replace and str_replace I opted now to use str_replace (cheers guys).In combination with htmlentities working well for website. The only thing is that there is this one character (’), which gives me a pain. The person I have built this website for (and who can update the content himself) often copies/pastes from Word. The ’ character comes in like this from Word and both preg_replace and str_replace do not replace the string with the replacement value '. What is wrong about my syntax?

echo "<p>";$str = htmlentities($row['text']);// Deal with ' from Word$webSafe = str_replace("’", "'", $str);// Deal with new lines etc$order   = array("\r\n", "\n", "\r");$replace = "<br />";$newstr = str_replace($order, $replace, $webSafe);// Deal with double <br />s$order2   = array("<br /><br />");$replace2 = "</p>\n<p>";$newstr2 = str_replace($order2, $replace2, $newstr);echo $newstr2;echo "</p>\n";

Also, feel free to let me know if my method of having three different replacements as such can be improved. I never worked much with those things in past and am always happy to do it in best way possible...Son

Link to comment
Share on other sites

Echo the value of $str after this line of code:$str = htmlentities($row['text']);I think you'll find that quote character has been transformed, which means str_replace can't find it the way you're searching for it. It's also possible that Microsoft saves that character as something else. Have you checked the value of $str before that line of code?

Link to comment
Share on other sites

Echo the value of $str after this line of code:$str = htmlentities($row['text']);I think you'll find that quote character has been transformed, which means str_replace can't find it the way you're searching for it. It's also possible that Microsoft saves that character as something else. Have you checked the value of $str before that line of code?
The problem occurs on text, which is fetched from db table (in which it was inserted with upload form). Copying the problematic character and pasting it in a string to compare a direct result of before and after str_replace I noticed that there is not even a problem to start off with (no question mark inside box instead of character displayed). Both strings (before and after) just look fine. It is just the text that comes from db, which causes issue (question mark inside box instead of character display). Does this make any sense?Edit as noticed one more interesting thing:Exporting the data from db to a spreadsheet to check the character it displays:’instead of the character.Does this help?Son
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...