Found a total of 10000 related content
How to Iterate through UTF-8 Strings Character by Character in PHP
Article Introduction:This article discusses the issue of accurately iterating through UTF-8 strings character by character in PHP. It highlights the limitations of using bracket indexing and presents preg_split as an effective solution that preserves character integrity
2024-10-23
comment 0
599
PHP get ASCII value of a character using ord
Article Introduction:The most direct way to get the ASCII value of a character in PHP is to use the ord() function, which returns the ASCII value of the first character of the string. 1.ord() receives a string parameter and only returns the ASCII value of the first character, such as ord('A') returns 65; 2. Be cautious when processing Chinese or special characters, because ord() only returns the first byte value of multi-byte characters, such as ord('In') returns 228; 3. Practical applications include judging character types and implementing simple encryption, such as judging whether it is a letter or number by comparing the ASCII range, or combining chr() to realize Caesar's password displacement.
2025-07-16
comment 0
889
php regex match anything until a character
Article Introduction:Matching "Arbitrary content up to a certain character" in PHP requires non-greed and forward-looking techniques. 1. Match until the colon can be preg_match('/^(.?):/',$str,$match), where ^ represents the beginning, (.?) non-greedy matches any character,: is the target character; 2. Use preg_match('/^(\D )/',$str,$match) to match the first number, and use preg_match('/^(.?)(?=\s)/',$str,$match); 3. Use forward-looking preg_match('/^(.?)(?=:)/',$str,$match) to avoid consumption of target words
2025-07-13
comment 0
818