What's the fastest way, in PHP, to determine if some given UTF-8 text is purely ASCII or not?
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
A possibly faster function would be to use a negative character class (since the regex can just stop when it hits the first character, and there's no need to internally capture anything):
Without regex (based on my comment) {
But I'd have to ask, why are you so concerned about faster? Use the more readable and easier to understand version, and only worry about optimizing it when you know it's a problem...
Edit:
Then the fastest will likely be
mb_check_encoding
:Check if any byte is greater than 0x7f, or any character is above U+007F.