Search code examples
phpstringechodir

Why does '\xa' not appear when outputting echo "C:\xampp\htdocs\practice\myOnlineStore";


This line of code

echo "C:\xampp\htdocs\practice\myOnlineStore";

outputs

C: mpp\htdocs\practice\myOnlineStore

Why is the \xa omitted from the output? Is there some sort of special character involved?


Solution

  • The \x is a escape sequence that means:

    After "\x", up to two hexadecimal digits are read (letters can be in upper or lower case). In UTF-8 mode, "\x{...}" is allowed, where the contents of the braces is a string of hexadecimal digits. It is interpreted as a UTF-8 character whose code number is the given hexadecimal number. The original hexadecimal escape sequence, \xhh, matches a two-byte UTF-8 character if the value is greater than 127.

    As the docs says here

    So you have to escape all escape chars on your string like:

    echo "C:\\xampp\\htdocs\\practice\\myOnlineStore";
    

    The \ is also an escape character.