Hi all,
I have data which is is captured from a serial post and the output is like this:
OBA178 O1745FS S0745 439 00 000 A3L28"
Is there a way to remove the serial control characters "" and "" from the string.
I have looked at a number of ways including "htmlentities" and "htmlspecialchars" but I can't see where they can help me.
Any ideas on how this can be don.
The control characters you're seeing didn't show up in your post - do you know their hex value in ASCII?
If so, you could simply do something like:
$data = str_replace(array("\x02", "\x04"), '', $data);
(where "\x02" is ASCII character 0x2).
Hi Brad,
Many thanks for your reply, I can find the ASCII values and give it a try. Looking at your code I think that should do the trick.
Many thanks,
Hi,
If you know what all the allowable characters are then you could filter out everything that isn't included in that list with preg_replace(); For example, if the allowable characters are letters, digits and spaces then...
$s = 'OBA178 O1745FS S0745 439 00 000 A3L28"'; $s = preg_replace('/[^a-zA-Z0-9 ]/', '', $s);
Does that help?