Connecting Tech Pros Worldwide Help | Site Map

Regular Characters to HTML entities

  #1  
Old May 11th, 2006, 05:15 PM
grantges@gmail.com
Guest
 
Posts: n/a
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

  #2  
Old May 11th, 2006, 05:35 PM
Justin Koivisto
Guest
 
Posts: n/a

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
  #3  
Old May 11th, 2006, 06:05 PM
Sandman
Guest
 
Posts: n/a

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]
  #4  
Old May 11th, 2006, 08:25 PM
grantges@gmail.com
Guest
 
Posts: n/a

re: Regular Characters to HTML entities


Excellent - thanks guys!

Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Regular expression to identify HTMLEncoded string Gabriela answers 2 November 4th, 2008 09:45 AM
XmlTextWriter Encodes HTML Entities? clintonG answers 6 June 1st, 2007 05:25 PM
convert special characters Frederik answers 5 November 16th, 2005 08:38 AM
decoding numeric HTML entities Andreas Gohr answers 10 July 23rd, 2005 09:37 PM