PHP: Replace Byte Sequence in String
Question by Guest | Last update on 2022-05-01 | Created on 2014-03-11
I would like to prepare some text using a PHP script so that it can be output.
Beyond usual ASCII and ANSI characters, the origin file contains some bytes and byte sequences, that cannot be displayed reasonably.
Therefore, I would like to replace some of those byte sequences (there are only a few) with displayable characters and letters.
I know all of the bytes and characters I would like to use for the replacement, but however, up to now, I have only replaced normal strings and characters using str_replace in PHP.
Hence my question is: How is it possible to replace, for example, the code points E2 80 93 with the character "-"?
Related Topics
How to Replace multiple Texts at the same Time
Tutorial | 0 Comments
Lazarus: Load File as Byte Array and save Byte Array as File
Tutorial | 0 Comments
Delphi/Lazarus: Show Byte Array as String of HEX Values
Tip | 0 Comments
PHP: Check Strings with Ctype-Functions for Character Classes
Article | 0 Comments
PHP: Fill Array with Sequence of Numbers or Characters
Tutorial | 0 Comments
PHP: Get first Digit of Number or String
Tutorial | 0 Comments
PHP: Remove arbitrary Characters at the Beginning and the End of a String
Tutorial | 0 Comments
Important Note
Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.
Participate
Ask your own question or write your own article on askingbox.com. That’s how it’s done.
If you have the hexadecimal code of a character (for example E2), the hexadecimal writing for this character would be \xE2 in PHP.
To replace a byte sequence consisting of multiple hexadecimal codes, you can just write several HEX-characters in a row:
This example would replace the byte sequence E2 80 93 in the string $s with "-".
Last update on 2022-10-31 | Created on 2014-03-14