0

I have tried this, but can't remove this kind of chars (……) from my string:

 $string= preg_replace('/[^a-zA-Z [\n\r] ]/', '', $string);
 $string= preg_replace('/\t\s\s+/', '', $string);
 $string= preg_replace("/[\n\r]/","=",$string);

it shows me my desired out, but I also want to remove special chars like: ……

Alex Kulinkovich
  • 4,408
  • 15
  • 46
  • 50
mubashermubi
  • 8,846
  • 4
  • 16
  • 30
  • 1
    It looks like you are interpreting UTF-8 text as ANSI. I think you should try `iconv` to convert the text to the right codepage. – GolezTrol Dec 14 '14 at 09:58
  • I tried this iconv('UTF-8', 'ASCII//TRANSLIT', $string) but still can't remove can you show me how to do with iconv? – mubashermubi Dec 14 '14 at 10:04
  • I don't see where you are removing those chars. [a-zA-Z] does not cover them. Think in the opposite way. Which chars you want to keep? and use preg_match instead. That will leave you just with what you need. – lepe Dec 14 '14 at 10:07
  • @lepe I just want to keep line breaks with strings. – mubashermubi Dec 14 '14 at 10:09
  • 3
    This looks like an encoding problem. Trying to solve this by "removing characters" is the absolutely wrong way to go about it. Learn about encodings, learn how to handle them correct: [What Every Programmer Absolutely, Positively Needs To Know About Encodings And Character Sets To Work With Text](http://kunststube.net/encoding/), http://stackoverflow.com/questions/279170/utf-8-all-the-way-through – deceze Dec 14 '14 at 10:24
  • @M3Dev: what do you mean by "strings"? Does string means to you [a-zA-Z0-9] ? – lepe Feb 25 '15 at 01:09

1 Answers1

0

This seems to work in an online tester

 $string= preg_replace('/[^a-zA-Z\n\r]/', '', $string);
RST
  • 3,899
  • 2
  • 20
  • 33