Reply to Re: Regular Characters to HTML entities

Your name:

Reply:


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 &#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


#!/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:

&#80;

&#72;&#101;&#108;&#108;&#111;&#32;&#109;&#97;&#116;&#101;&#33;



--
Sandman[.net]

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация