|
Posted by Sandman on 11/19/11 11:47
In article <1147363832.905465.105550@j33g2000cwa.googlegroups.com>,
"grantges@gmail.com" <grantges@gmail.com> wrote:
> Hi -
>
> Does anyone know of a php function that takes a given character - ex.
> "A" without quotes and converts it into A ?
>
> If not a single function, what is the best way to accomplish this. The
> htmlentities function suite handle special characters, but my goal is
> to change average everyday letters of the alphabet as well.
>
> Thanks -
> Bert
#!/usr/bin/php
<?
print str_to_ascii("P");
print "\n";
print str_to_ascii("Hello mate!");
function str_to_ascii($string){
$chars = preg_split('//', $string, -1, PREG_SPLIT_NO_EMPTY);
foreach ($chars as $char){
$ret .= "&#" . ord($char) . ";";
}
return $ret;
}
?>
Outputs:
P
Hello mate!
--
Sandman[.net]
[Back to original message]
|