Page 1 of 1
Printing ASCII characters to a document?
Posted: Sun Apr 17, 2005 2:44 pm
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 # somehow...
I've seen this somewhere before but I can't find it now... Been a long day *yawn*
...
Posted: Sun Apr 17, 2005 2:47 pm
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...
Posted: Sun Apr 17, 2005 2:50 pm
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?
Posted: Sun Apr 17, 2005 2:59 pm
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