I have some text saved in database and i want to replace few srtings in it For example i have text in database: "Översikt: Hotell Strand Palace är beläget mitt i Londons centrum" I want to repalce "Översikt" with "Hello" using str_replace but it does not work. When i echo it shows me: "
i could find replacement for diamond in html special characters but could not find for diamond with a question mark inside
most likely you have a character encoding issue between the database and your PHP string. The extended character for Ö is different in ISO-8859-1, UTF-8, Windows-1252, and of course the latin1_swedish_ci that is the default in mySQL... You need to make sure your PHP code and your database are using the same encoding.
I always try to keep it a habit to use MB functions when dealing with non Latin languages. Assuming you got utf-8 encoded text: <?php // Set your encoding (incase you need to change it) mb_internal_encoding("UTF-8"); mb_regex_encoding("UTF-8"); $text = "Översikt: Hotell Strand Palace är beläget mitt i Londons centrum"; $englishText = mb_ereg_replace('Översikt','Hello', $text); echo $text . '<br />' . $englishText . '<br />'; PHP:
I am using "Collation: latin1_swedish_ci" in mysql database. what should i use on my php and html page? thank you
db is latin character set and web page is utf8 character set. that's why its creating problem for me. What if i convert my db table to utf-8 swedish? becaseu my language is swedish. thank you
Instead of this <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> PHP: Use this <meta http-equiv="Content-Type" content="text/html; charset=charset=ISO-8859-1" /> PHP: