1

I have a text file containing this; "I do not know" character. Already search on google but I'm having hard time getting desired search result since I do not know what is the general term for this kind of character.

enter image description here

I tried removing it using below code but nothing happens. I also tried "\f" because I thought that character is form feed but still can't remove.

$replace = str_replace("\0", ' ', $str);  

EDIT:

The said character is really form feed but somehow below code is not working for me.

$replace = str_replace("\f", ' ', $str);  
Ceeee
  • 1,392
  • 2
  • 15
  • 32

3 Answers3

3

You can use prep_replace command to perform a regular expression search and replace.

$replace = preg_replace( '/[^A-Za-z0-9 _\-\+\&]/', '',$str);

Note: You need to decide the first parameter to the preg_replace function call for the set of unwanted characters you don't want. You might be interested to remove non printable characters.

Rajat Paliwal
  • 634
  • 7
  • 11
  • Thank you very much Sir. I also tried this but the 'NUL' character and 'FF' still showing when I use this. I'll try other regex pattern and thank you again – Ceeee Aug 05 '16 at 07:11
0

I do not know why, but using str_replace is not working to remove the 'FF' (Form Feed) character

$replace = str_replace("\f", ' ', $str); // not working

Using below code solves my problem but kinda not look good because it is using regex to replace a single character only. Still, this works:

$replace = preg_replace('/[\f]/', " ", $str);
Ceeee
  • 1,392
  • 2
  • 15
  • 32
-1

Seems like an issue with your header. Try once after adding this on you header.

header('Content-Type: text/html; charset=UTF-8');

Hope this helps

Aravind Pillai
  • 739
  • 7
  • 21