Jump to content

Stripping out control(?) characters


Pikachu2000

Recommended Posts

I have a text file that gets parsed out into an array, then is going to be dumped into a DB table. The file comes from a third party data feed. In the file, there are occasionally control characters (at least I think that's what they are) such as: ^ß that echo in the browser as the black diamond with the question mark. They are unnecessary for my purposes, and I'd like to get rid of them before inserting the data to the table. What function(s) should I be looking at for this?

Link to comment
https://forums.phpfreaks.com/topic/205233-stripping-out-control-characters/
Share on other sites

Well, put it this way. I'm sure all htmlentities() come out as the form:

 

&[stuff];

 

Right? After using the function, try a preg_replace with a pattern such as...

 

$pattern = '/(&.*?;)/';

 

The .* is a greedy operator. Combine it with ?; to make it match everything up to the ";". It should work.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.