for($i = 0; $i < 255; $i++)
if (preg_match('@[[:print:]]@', chr($i))) echo "chr($i) matches :print:<br>"; else echo "chr($i) doesnt match :print:<br>";
On my Windows system, the output for chr(9)
is:
chr(9) matches :print:
With the same code, on a Linux system, the output is:
chr(9) doesnt match :print:
Why does the :print:
class match \t
on Windows only?
Use \t to match a tab character (ASCII 0x09), \r for carriage return (0x0D) and \n for line feed (0x0A).
preg_match stops looking after the first match. preg_match_all , on the other hand, continues to look until it finishes processing the entire string. Once match is found, it uses the remainder of the string to try and apply another match.
Definition and Usage The preg_match() function returns whether a match was found in a string.
The preg_match() function will tell you whether a string contains matches of a pattern.
It could be a locale issue, but then you must have a very funky locale on your hands. POSIX says that no cntrl
can be print
, and no space
or blank
can be print
unless it's the space character itself. In the "C"
locale, tab is all of cntrl
, space
, and blank
; it seems like a very strange locale that would consider it none of those.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With