Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/81.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_Html_Optimization_Buffer - Fatal编程技术网

Php 这个HTML优化代码的开头是做什么的?

Php 这个HTML优化代码的开头是做什么的?,php,html,optimization,buffer,Php,Html,Optimization,Buffer,困难的部分是试图找出stripwhitespace()函数的作用。stripbuffer()相当简单,但我已经盯着这段代码看了一段时间了,现在试图破译它,但没有用。含糊不清的变量名和缺少注释也没有多大帮助。我还不得不删除一些超链接,因为在这个网站上防止垃圾邮件 这肯定是一个混乱,但它似乎从字符串中去除了不必要的空白,除了文本区域内的空白。这肯定是一个混乱,但它似乎从字符串中去除了不必要的空白,除了文本区域内的内容。在我看来,它似乎能处理文本区域之前和之后的所有内容,但它只处理文本区域的内容 虽然

困难的部分是试图找出stripwhitespace()函数的作用。stripbuffer()相当简单,但我已经盯着这段代码看了一段时间了,现在试图破译它,但没有用。含糊不清的变量名和缺少注释也没有多大帮助。我还不得不删除一些超链接,因为在这个网站上防止垃圾邮件


这肯定是一个混乱,但它似乎从字符串中去除了不必要的空白,除了文本区域内的空白。

这肯定是一个混乱,但它似乎从字符串中去除了不必要的空白,除了文本区域内的内容。

在我看来,它似乎能处理文本区域之前和之后的所有内容,但它只处理文本区域的内容

虽然这段代码可能有点有趣,但众所周知PHP在快速字符串操作方面非常糟糕,所有那些str_replace调用都是一个糟糕的主意


我预测,通过在web服务器上使用gzip/deflate在发送之前压缩脚本输出,您将获得更好的性能。

在我看来,它似乎处理了textarea之前和之后的所有内容,但只处理textarea的内容

虽然这段代码可能有点有趣,但众所周知PHP在快速字符串操作方面非常糟糕,所有那些str_replace调用都是一个糟糕的主意


我预测,通过在web服务器上使用gzip/deflate在发送之前压缩脚本输出,您将获得更好的性能。

显然
stripBuffer
的作用是:它尝试从输入中去除所有空白

stripwhitespace
的工作原理如下:

function stripwhitespace($input){
    $currentPosition=0; // start from the first char
    $endPosition=strlen($input)-1; // where to stop
    $returnValue="";

    // while there is more input to process
    while($currentPosition<$endPosition){
        // find start of next <textarea> tag
        $startOfNextTextarea=stripos($input,"<textarea",$currentPosition);
        if($startOfNextTextarea===false){
            // no textarea tag remaining:
            // strip ws from remaining input, append to $returnValue and done!
            $bufferToStrip=substr($input,$currentPosition);
            $temp=stripBuffer($bufferToStrip);
            $returnValue.=$temp;
            $currentPosition=$endPosition; // to cause the function to return
        }
        else{
            // <textarea> found
            // strip ws from input in the range [current_position, start_of_textarea)
            $bufferToStrip=substr($input,$currentPosition,$startOfNextTextarea-$currentPosition);
            // append to return value
            $temp=stripBuffer($bufferToStrip);
            $returnValue.=$temp;
            $endOfNextTextarea=stripos($input,"</textarea>",$startOfNextTextarea);
            // get contents of <textarea>, append to return value without stripping ws
            $temp=substr($input,$startOfNextTextarea,$endOfNextTextarea-$startOfNextTextarea);
            $returnValue.=$temp;
            // continue looking for textareas after the end of this one
            $currentPosition=$endOfNextTextarea;
        }
    }
    return $returnValue;
}
函数条带空白($input){
$currentPosition=0;//从第一个字符开始
$endPosition=strlen($input)-1;//在哪里停止
$returnValue=“”;
//虽然有更多的输入要处理

而($currentPosition很明显,
stripBuffer
的作用是:它试图从输入中去除所有空白

stripwhitespace
的工作原理如下:

function stripwhitespace($input){
    $currentPosition=0; // start from the first char
    $endPosition=strlen($input)-1; // where to stop
    $returnValue="";

    // while there is more input to process
    while($currentPosition<$endPosition){
        // find start of next <textarea> tag
        $startOfNextTextarea=stripos($input,"<textarea",$currentPosition);
        if($startOfNextTextarea===false){
            // no textarea tag remaining:
            // strip ws from remaining input, append to $returnValue and done!
            $bufferToStrip=substr($input,$currentPosition);
            $temp=stripBuffer($bufferToStrip);
            $returnValue.=$temp;
            $currentPosition=$endPosition; // to cause the function to return
        }
        else{
            // <textarea> found
            // strip ws from input in the range [current_position, start_of_textarea)
            $bufferToStrip=substr($input,$currentPosition,$startOfNextTextarea-$currentPosition);
            // append to return value
            $temp=stripBuffer($bufferToStrip);
            $returnValue.=$temp;
            $endOfNextTextarea=stripos($input,"</textarea>",$startOfNextTextarea);
            // get contents of <textarea>, append to return value without stripping ws
            $temp=substr($input,$startOfNextTextarea,$endOfNextTextarea-$startOfNextTextarea);
            $returnValue.=$temp;
            // continue looking for textareas after the end of this one
            $currentPosition=$endOfNextTextarea;
        }
    }
    return $returnValue;
}
函数条带空白($input){
$currentPosition=0;//从第一个字符开始
$endPosition=strlen($input)-1;//在哪里停止
$returnValue=“”;
//虽然有更多的输入要处理
而($currentPosition在伪代码(ish)中)

嗯-作为一个html压缩器,这段代码本身实际上是臃肿且难以阅读的。正则表达式如果使用得当,应该能够更好地处理这一问题。

在伪代码(ish)中


嗯-作为一个html压缩器,这段代码本身实际上很臃肿,也很难阅读。正则表达式如果使用得好,应该可以做得更好。

至少要格式化你的代码。而且人们可能不会太赞同帮你去模糊代码。@Robert,我已经为他格式化了,代码并没有被混淆。它只是写得不好(变量名不好,没有注释。)@simshaun,谢谢。我自己尝试过格式化它,我想我做到了。它只是变得很混乱。至少格式化你的代码。而且人们可能不会太同情帮助你去消费代码。@Robert,我为他格式化了它,代码没有混淆。它只是写得不好(变量名不正确,缺少注释。)“SimSunun,谢谢。我试过格式化它,我想我做了。它只是变得混乱。哇。谢谢你的信息。我认为PHP可以节省足够的空间,减少下载时间可以证明增加的处理时间,但我不认为PHP会这么慢。同意。使用GZIP压缩输出而不是C。ode代码段。根据php.net,gzip压缩会导致很多错误。你是在说ob_gzhandler吗?@Ajson:你的web服务器没有压缩输出的方法吗?不,不是在说ob_gzhandler。这是一个自制的web服务器。我是个爱好者,不是专业人士。哦,哇。谢谢你的信息。我觉得php可以节省足够的资源空间减少下载时间可以证明增加的处理时间,但我不认为PHP会这么慢。同意。使用GZIP压缩输出而不是那个代码片段。根据PHP.NET,GZIP压缩会导致相当多的错误。你在说OBAGZHANDLER吗?@ AJSON:你的Web服务器没有办法吗?压缩输出?不,不是说ob_gzhandler。这是一个自制的网络服务器。我是一个爱好者,不是专业人士。
bff is the initial buffer
pzcr is the current start
pzed is the current end
rst will have the filtered text appended to it.
while the current start is before the end
  t_pos_start is first position of the textarea (after current start)
  if there is no text area found
    bffstp becomes the substring of the buffer starting at pzcr
    temp is buffer stripped.
    append temp to rst
    set the current start to the current end.
  else
    set bffstp to the substr between the start and the start of the textarea tag
    temp is buffer stripped.
    append temp to rst
    skip the textarea
    temp will be the substr from the start of the text area to the closing text area tag.
    append temp (unfiltered) to rst.
    set the next start to the end of the textarea (at the start of its closing tag).
  end the if
end the while
return the appended buffer (rst)