- array_map: documentation ( source)
- var_dump: documentation ( source)
- preg_match: documentation ( source)
- implode: documentation ( source)
<?php
$foo = "🚁- Tour @exslagermaurice";
function is_ascii( $str )
{
return ( bool ) !preg_match( '/[\x80-\xFF]/' , $str );
}
/**
* utf8_single_chr_html_encode( )
*
* Converts a UTF-8 character to HTML Numbered Entity like {
* @since 1.0
*
* @param string $chr The Unicode character to be encoded as numbered entity
* @return string HTML numbered entity
*/
function utf8_single_chr_html_encode( $chr )
{
return '&#' . utf8_ord( $chr ) . ';';
}
/**
* utf8_html_encode( )
*
* Converts a UTF-8 string to a series of
* HTML Numbered Entities like {'ی...
* @since 1.0
*
* @param string $str The Unicode string to be encoded as numbered entities
* @return string HTML numbered entities
*/
function utf8_html_encode( $str )
{
return implode( array_map( 'utf8_single_chr_html_encode' , utf8_split( $str ) ) );
}
var_dump(utf8_html_encode($foo));