如何在PHP中将字符串转换为小大写字母?

如何在PHP中将字符串转换为小大写字母?,php,string-conversion,smallcaps,Php,String Conversion,Smallcaps,我试图用PHP将由“标准”大小写字母组成的横线转换成小大写字母。在php.net文档中没有关于小型股的信息 根据我的理解,小型大写字母是: Hᴇʟʟᴏ ᴛʜᴇʀᴇ (使用此网站生成:) 例如,以下是at的小盘股版本: 我在网上搜索了很长时间,但在PHP中没有发现任何东西。我知道CSS让你通过使用 font-variant: small-caps; 但我需要在服务器端完成这项工作。这在PHP中可能吗 编辑:为了完成我的问题,我正在尝试生成纯文本。因此,在我的例子中,没有HTML、图像或CSS是可

我试图用PHP将由“标准”大小写字母组成的横线转换成小大写字母。在php.net文档中没有关于小型股的信息

根据我的理解,小型大写字母是:

Hᴇʟʟᴏ ᴛʜᴇʀᴇ

(使用此网站生成:)

例如,以下是a
t
的小盘股版本:

我在网上搜索了很长时间,但在PHP中没有发现任何东西。我知道CSS让你通过使用

font-variant: small-caps;
但我需要在服务器端完成这项工作。这在PHP中可能吗

编辑:为了完成我的问题,我正在尝试生成纯文本。因此,在我的例子中,没有HTML、图像或CSS是可能的

编辑2:在链接的网站上,使用Javascript函数转换文本

代码如下:

function encool() {
    var _0xce74x20 = location[_0x804c[82]],
        _0xce74x21;
    if (_0xce74x20[_0x804c[84]](_0x804c[83]) == -1 && _0xce74x20[_0x804c[84]](_0x804c[85]) == -1 && _0xce74x20[_0x804c[84]](_0x804c[86]) == -1 && _0xce74x20[_0x804c[84]](_0x804c[87]) == -1 && _0xce74x20[_0x804c[84]](_0x804c[88]) == -1) {
        _0xce74x21 = document[_0x804c[91]][_0x804c[90]][_0x804c[89]]
    } else {
        _0xce74x21 = change(decomposeAString(document[_0x804c[91]][_0x804c[90]][_0x804c[89]]))
    };
    document[_0x804c[91]][_0x804c[92]][_0x804c[89]] = _0xce74x21
}

他肯定在使用角色映射。如果我找到了解决方案,我会研究一下,然后发布解决方案。

因此,您希望使用UNICODE将包含小写字母和大写字母的文本转换为小写字母

为此,您需要一个映射表,该表将每个字符映射到UNICODE中的小大写字母。用于在PHP中进行转换


请参阅PHP文档中有关如何使用自定义映射表的内容。

因此,您希望使用UNICODE将包含小写字母和大写字母的文本转换为小写字母

为此,您需要一个映射表,该表将每个字符映射到UNICODE中的小大写字母。用于在PHP中进行转换


请参阅PHP文档中有关如何使用自定义映射表的部分。

映射每个字符,然后在字符串上循环

<?php
//Initialize the map
$map = array(
    "A"=>"ᴀ",
    "B"=>"ʙ",
    "C"=>"ᴄ",
    "D"=>"ᴅ"
    //etc
    );

function convertToSmall($string,$map){   
    //Our string to return
    $return = "";
    //You can replace length + the for loop for an explode + foreach
    $length = strlen($string);
    for($i = 0; $i<$length; $i++){
        //set our input character
        $input = strtoupper($string[$i]);
        //check if its in the map
        if(isset($map[$input])){
            $input = $map[$input];
        } 
        //write to our output
        $return .= $input;

    }

    return $return;

}

print_r(convertToSmall("aa bc da",$map));    

映射每个字符,然后在字符串上循环

<?php
//Initialize the map
$map = array(
    "A"=>"ᴀ",
    "B"=>"ʙ",
    "C"=>"ᴄ",
    "D"=>"ᴅ"
    //etc
    );

function convertToSmall($string,$map){   
    //Our string to return
    $return = "";
    //You can replace length + the for loop for an explode + foreach
    $length = strlen($string);
    for($i = 0; $i<$length; $i++){
        //set our input character
        $input = strtoupper($string[$i]);
        //check if its in the map
        if(isset($map[$input])){
            $input = $map[$input];
        } 
        //write to our output
        $return .= $input;

    }

    return $return;

}

print_r(convertToSmall("aa bc da",$map));    

好的,这是我提出的解决方案,但它不是很完整,因为即使它符合我的需要。我需要这个来转换小文本(类别名称),这样我就可以了

function convertToSmallCaps($string) {
    // standar capitals
    $caps = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z');
    // small capitals
    $smallCaps = array('ᴀ', 'ʙ', 'ᴄ', 'ᴅ', 'ᴇ', 'ꜰ', 'ɢ', 'ʜ', 'ɪ', 'ᴊ', 'ᴋ', 'ʟ', 'ᴍ', 'ɴ', 'ᴏ', 'ᴘ', 'ǫ', 'ʀ', 's', 'ᴛ', 'ᴜ', 'ᴠ', 'ᴡ', 'x', 'ʏ', 'ᴢ');

    // remove all chars except [a-z] and - (replacing dashes with spaces)
    $sanitized_string = str_replace('-',' ',sanitize_title($string));

    // convert to uppercase
    $sanitized_string = mb_strtoupper($string);

    $length = strlen($sanitized_string);
    $output_string='';
    for($i = 0; $i<$length; $i++){
        $char = $sanitized_string[$i];
        // If the letter exsist in small capitals
        $letter_position = array_search($char,$caps);
        if(is_numeric($letter_position) && isset($smallCaps[$letter_position])) {
            // We append it to the ouput string
            $output_string.=$smallCaps[$letter_position];

        } else {
            // or else we append the original char to the output string
            $output_string.=$char;
        }
    }
    // return the converted string
    return $output_string;
}
函数convertToSmallCaps($string){
//标准首都
$caps=数组('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
//小首都
$smallCaps=数组('s)ᴀ', 'ʙ', 'ᴄ', 'ᴅ', 'ᴇ', 'ꜰ', 'ɢ', 'ʜ', 'ɪ', 'ᴊ', 'ᴋ', 'ʟ', 'ᴍ', 'ɴ', 'ᴏ', 'ᴘ', 'ǫ、ʀ、s、'ᴛ', 'ᴜ', 'ᴠ', 'ᴡ', '“x”,“ʏ”,“ʏ”ᴢ');
//删除除[a-z]和-(用空格替换破折号)之外的所有字符
$sanitized_string=str_replace('-','',sanitized_title($string));
//转换成大写
$sanitized_string=mb_strotupper($string);
$length=strlen($sanitized_string);
$output_string='';

对于($i=0;$iOk),这是我提出的解决方案,但它不是很完整,因为即使它符合我的需要。我需要它来转换小文本(类别名称),所以它对我来说是可以的

function convertToSmallCaps($string) {
    // standar capitals
    $caps = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z');
    // small capitals
    $smallCaps = array('ᴀ', 'ʙ', 'ᴄ', 'ᴅ', 'ᴇ', 'ꜰ', 'ɢ', 'ʜ', 'ɪ', 'ᴊ', 'ᴋ', 'ʟ', 'ᴍ', 'ɴ', 'ᴏ', 'ᴘ', 'ǫ', 'ʀ', 's', 'ᴛ', 'ᴜ', 'ᴠ', 'ᴡ', 'x', 'ʏ', 'ᴢ');

    // remove all chars except [a-z] and - (replacing dashes with spaces)
    $sanitized_string = str_replace('-',' ',sanitize_title($string));

    // convert to uppercase
    $sanitized_string = mb_strtoupper($string);

    $length = strlen($sanitized_string);
    $output_string='';
    for($i = 0; $i<$length; $i++){
        $char = $sanitized_string[$i];
        // If the letter exsist in small capitals
        $letter_position = array_search($char,$caps);
        if(is_numeric($letter_position) && isset($smallCaps[$letter_position])) {
            // We append it to the ouput string
            $output_string.=$smallCaps[$letter_position];

        } else {
            // or else we append the original char to the output string
            $output_string.=$char;
        }
    }
    // return the converted string
    return $output_string;
}
函数convertToSmallCaps($string){
//标准首都
$caps=数组('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
//小首都
$smallCaps=数组('s)ᴀ', 'ʙ', 'ᴄ', 'ᴅ', 'ᴇ', 'ꜰ', 'ɢ', 'ʜ', 'ɪ', 'ᴊ', 'ᴋ', 'ʟ', 'ᴍ', 'ɴ', 'ᴏ', 'ᴘ', 'ǫ、ʀ、s、'ᴛ', 'ᴜ', 'ᴠ', 'ᴡ', '“x”,“ʏ”,“ʏ”ᴢ');
//删除除[a-z]和-(用空格替换破折号)之外的所有字符
$sanitized_string=str_replace('-','',sanitized_title($string));
//转换成大写
$sanitized_string=mb_strotupper($string);
$length=strlen($sanitized_string);
$output_string='';

对于($i=0;$i是否要将文本显示为图像,或者只是更改特定元素的样式?是否可以向元素添加类或id,并对该类或id使用CSS规则?或者甚至向元素添加
style
属性?但我需要在服务器端执行此操作,因为我所做的工作没有多大帮助。只需在您的周围打印一个样式标记即可输出或者给它一个css类?你可以分割每个字符,并将其更改为同一字符的unicode版本。当一个样式规则(如你所示)出现时,似乎需要花费很多精力可能是更好的方法。显然,解决方案是每个字符都有一个映射到其unicode小大写挂件,然后将该映射应用到每个字符串。作者在这里。是的,在FSymbols上,我首先分解重音字符(如ș)转换为重音符号+普通字母-这可能是您没有注意到的功能-然后将小写字母转换为类似的小写字母。您可以使用该工具本身编译转换表。您想将文本显示为图像还是只更改特定元素的样式?您不能向元素添加类或id并使用C吗SS为该类或id制定规则?或者甚至为元素添加
style
属性?但我需要在服务器端这样做,因为我所做的并没有多大帮助。只需在输出周围打印一个样式标记,或者给它一个css类?您可以拆分每个字符,并将其更改为同一字符的unicode版本。看起来有很多问题需要解决f使用样式规则(如您所示)是更好的方法。显然,解决方案是将每个字符映射到unicode中的小大写挂件,然后将该映射应用到每个字符串。作者在这里。是的,在FSymbols上,我首先分解重音字符(如ș)转换为重音符号+普通字母-这可能是您没有注意到的功能-然后将小写字母转换为类似的小写字母。您可以使用该工具本身编译转换表。这很有趣。而且非常简单(在此之前,我需要去掉所有重音字符,但这是一个很好的起点!)这很有趣。而且非常简单(在此之前,我需要去掉所有强调字符,但这是一个很好的起点!)请将此解决方案或提供的其他解决方案之一标记为已解决,以便结束此主题。请将此解决方案或提供的其他解决方案之一标记为sol