Printing ASCII characters to a document?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Printing ASCII characters to a document?

Post by Chris Corbyn »

This probably applies to any language but how do I print an ascii character in PHP?

Like:

Code: Select all

"\r\n" //Carriage return

"#" => html special char hash mark

"\x035" //I want an ascii equivalent of &#035 somehow...
I've seen this somewhere before but I can't find it now... Been a long day *yawn*
User avatar
Cinder
Forum Newbie
Posts: 6
Joined: Sun Apr 17, 2005 2:09 pm
Location: Uknown

...

Post by Cinder »

Have a look at the ord() function in the php manual:

http://no2.php.net/manual/en/function.ord.php

---

Edit: Read your post again (misunderstood).. Maby you can look at the charmap...
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

He he...

Got me in the right direction... I needed the reverse chr().

Welcome on board Cinder ;-)

EDIT | This does fix my problem but now that my curiosity is peaked... does anybody know how to just print it directly?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Just in case this might come in useful to anybody....


To convert ALL numeric html character codes to ascii character's (thanks to Cinder getting me there)... do this...

Code: Select all

$converted = preg_replace('/\&\#(\d+)\;/e', "chr(\\1)", $input_string);
I needed this because html_entity_decode() wasn't doing the job...

EDIT | Added the e modifier... curtosy of feyd
Post Reply