Connecting Tech Pros Worldwide Help | Site Map

Regular Characters to HTML entities

 
LinkBack Thread Tools Search this Thread
  #1  
Old May 11th, 2006, 04:15 PM
grantges@gmail.com
Guest
 
Posts: n/a
Default Regular Characters to HTML entities

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, 04:35 PM
Justin Koivisto
Guest
 
Posts: n/a
Default 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, 05:05 PM
Sandman
Guest
 
Posts: n/a
Default 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, 07:25 PM
grantges@gmail.com
Guest
 
Posts: n/a
Default Re: Regular Characters to HTML entities

Excellent - thanks guys!

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.