0

In my below code I am replacing . with a non-breaking space using  

$orginal_startString = str_replace('.',' ',$startString);

This works fine in windows and save in database but in linux it's not woking properl it's replacing . with special character Â.

skaffman
  • 398,947
  • 96
  • 818
  • 769
Vinod HC
  • 1,557
  • 5
  • 20
  • 38
  • Please show your code and an example – Pekka May 16 '11 at 12:43
  • My code : $startString = "Apple..."; $orginal_startString = str_replace('.',' ',$startString); In database it is storing with special chracter Apple   – Vinod HC May 16 '11 at 12:45
  • This sounds more like an encoding problem - where do those dots come from? They are not normal `.` dots, are they? – Pekka May 16 '11 at 12:48
  • 2
    Sounds like you've actually replaced with the actual non-breaking space character (rather than the named entity), in addition, it sounds like you've got a character encoding issue, and UTF-8 encoding text is being interpreted as codepage 1252 – Rowland Shaw May 16 '11 at 12:49
  • yes might be I am usin "latin1_swedish_ci" but i have no issues in my local machine only in server I face this problem.. In server alos they r usin same collation type.. I have no idea how to solve now. – Vinod HC May 16 '11 at 15:00

1 Answers1

0

If you want space as text not HTML, Use the hex equivalent 0x20.

$orginal_startString = str_replace('.',chr(0x20),$startString);

And check this HTML encoding issues - "Â" character showing up instead of " "

Community
  • 1
  • 1
0xAli
  • 1,059
  • 10
  • 22
  • I tried hex equivalent 0x20. But in db it's not treating as a space character. for eg After apple if i have 2 spaces, spaces are not stored in db. – Vinod HC May 16 '11 at 13:07
  • And do you want to keep two spaces or one? you can replace every two dots [..] with one dot [.] till there is no two dots, then replace the space. and check http://stackoverflow.com/questions/2515905/a-in-my-html-after-purify – 0xAli May 16 '11 at 13:46
  • For each dot I need each space in the db. – Vinod HC May 16 '11 at 14:04
  • $startString = 'I ate apple....You should eat it too.|.|'; $orginal_startString = str_replace('.',chr(0x20),$startString); print $orginal_startString; ?> view the source it's as you want it. can i see the INSERT mysql query, and the database charset/structure. – 0xAli May 16 '11 at 14:43
  • I am usin "latin1_swedish_ci" but i have no issues in my local machine only in server I face this problem.. In server alos they r usin same collation type.. I have no idea how to solve now. – Vinod HC May 16 '11 at 15:03
  • What's the character encoding of the pages? Add this to the server page HTML – 0xAli May 16 '11 at 15:16
  • I am using smarty templates: – Vinod HC May 16 '11 at 15:23
  • sir That has nothing to do with the encoding. check between the `` and `` for the meta charset code, if it's not there just paste – 0xAli May 16 '11 at 16:59
  • Thank u sir, I tried this but no luck still in database it store as  – Vinod HC May 17 '11 at 10:21