Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php函数将选项卡等编码为html_Php_Escaping - Fatal编程技术网

Php函数将选项卡等编码为html

Php函数将选项卡等编码为html,php,escaping,Php,Escaping,我正在寻找一个函数,将空格、制表符等编码为html字符 例如,获取字符串集合: Whats up?&^5@# number pie word 1 3 hi 2 4 no 我处理的是: $outString=""; for($i=0;$i<count($strArr);$i++){ $outString.= somefunc($strArr[$i]);//what should somefunc be

我正在寻找一个函数,将空格、制表符等编码为html字符

例如,获取字符串集合:

        Whats up?&^5@#
number  pie     word
1       3       hi
2       4       no
我处理的是:

$outString="";
for($i=0;$i<count($strArr);$i++){
    $outString.= somefunc($strArr[$i]);//what should somefunc be?
 }
$outString=”“;

对于($i=0;$iHTML没有任何表示制表位的方法,因此这本身是无法实现的


您可以将内容包装在
元素中,但最好通过
分解制表符上的每一行,然后从生成的数据结构中生成

您是否看到或?

您将无法在html中创建制表符,但如果您将所有制表符都更改为html表,则应该可以。试着这样做:

function foo($string) {
    $table='<table border="0">'.htmlentities($string).'</table>';
    $table=preg_replace( "#\r\n#", "</td></tr><tr><td>", $table);
    $table=preg_replace( "#\t#", "</td><td>", $table);

    return $table;
}
函数foo($string){ $table=''.htmlentities($string)。''; $table=preg#u replace(“#\r\n#”,”,$table); $table=preg#U replace(“#\t#“,”,$table); 返回$table; }
您是否试图将空格(等)替换为您选择的字符?HTML中的制表符是什么?这是干什么用的?您最终用
$outString
做什么?它是一个预格式化的字符串,格式有点随机(包括任意制表符间距以生成表。目前我使用
标记,但我正试图改变这种做法。