Connecting Tech Pros Worldwide Forums | Help | Site Map

Regular Characters to HTML entities

grantges@gmail.com
Guest
 
Posts: n/a
#1: May 11 '06
Hi -

Does anyone know of a php function that takes a given character - ex.
"A" without quotes and converts it into &#65 ?

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


Justin Koivisto
Guest
 
Posts: n/a
#2: May 11 '06

re: Regular Characters to HTML entities


grantges@gmail.com wrote:[color=blue]
> Hi -
>
> Does anyone know of a php function that takes a given character - ex.
> "A" without quotes and converts it into &#65 ?
>
> 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
>[/color]

function str2entities($email){
$str='';
for($j=0;$j<strlen($email);++$j){
$str.='&#'.ord($email{$j}).';';
}
return $str;
}


--
Justin Koivisto, ZCE - justin@koivi.com
http://koivi.com
Sandman
Guest
 
Posts: n/a
#3: May 11 '06

re: Regular Characters to HTML entities


In article <1147363832.905465.105550@j33g2000cwa.googlegroups .com>,
"grantges@gmail.com" <grantges@gmail.com> wrote:
[color=blue]
> Hi -
>
> Does anyone know of a php function that takes a given character - ex.
> "A" without quotes and converts it into &#65 ?
>
> 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[/color]


#!/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]
grantges@gmail.com
Guest
 
Posts: n/a
#4: May 11 '06

re: Regular Characters to HTML entities


Excellent - thanks guys!

Closed Thread