0

Есть ли функция в PHP, которая из подобного: "чтобы..." делает "&# x447;&# x442;&# x43e;&# x431;&# x44b;..." (Тут с пробелами после #) ?

2 ответа 2

0

прочтите про htmlentities() и html_entity_decode(), они работают с html-сущностями: http://php.net/manual/ru/function.htmlentities.php

0

Код. Вроде работает...

mb_internal_encoding( 'UTF-8' );
function orduni( $s ){
    $c = ord( $s );
    if( $c >= 128 ){
        $o = 0;
        if( $c < 224 ){ $b = 2; }elseif( $c < 240 ){ $b = 3; }elseif( $c < 248 ){ $b = 4; }
        $t = $c - 192 - ( $b > 2 ? 32 : 0 ) - ( $b > 3 ? 16 : 0 );
        for( $i = 2; $i <= $b; $i++ ){
            $o++;
            $v = ord( substr( $s, $o, 1 ) ) - 128;
            $t = $t * 64 + $v;
        }
        return $t;
    }
    return $c;
}
function html16( $s ){
    $l = mb_strlen( $s );
    $r = '';
    for( $i = 0; $i < $l; $i++ ){
        $r .= '&#' . orduni( mb_substr( $s, $i, 1 ) ) . ';';
    }
    return $r;
}
echo html16( 'Привет' );

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.