-1

I want to echo a crude directory structure. Using the ascii characters 192 and 195. How can I do this? I just end up with an invalid character � when using chr(192);. I've tried using mb_convert_encoding but that didnt work either. Any solutions?

Chud37
  • 4,907
  • 13
  • 64
  • 116

1 Answers1

5

I assume by "ASCII characters 192 and 195" you mean └ and ├. Well, those aren't "ASCII", since ASCII only includes 128 characters. It's "Extended ASCII" if anything, but the term "Extended ASCII" doesn't mean anything either since ASCII has been extended hundreds of times and it's undefined what extension exactly you mean. This is likely the issue with you trying to convert the encoding, you really have no idea what you're converting from.

The simplest thing would be to use those characters as plain text:

echo '└';
echo '├';

This requires that your text editor supports the characters, that you're saving the file in an encoding that supports the characters (I recommend UTF-8), and that you're serving the file with the appropriate HTTP headers/meta tags denoting it to be the encoding it's in (e.g. UTF-8).

You could also encode the characters as such in PHP string literals:

echo "\xe2\x94\x94";
echo "\xe2\x94\x9c";

That outputs them as UTF-8 and you will still need to care about declaring your file to be UTF-8 encoded in headers/meta tags.

Or you output them as HTML entities:

echo '├';
echo '└';

This doesn't require any special considerations with regards to file encodings, but is only meaningful in an HTML context.

deceze
  • 510,633
  • 85
  • 743
  • 889