有没有人能翻译一下这段,有点看不懂谢谢谢谢谢谢

来源:4-1 cookie简介

慕九州9431754

2018-11-26 12:43

<?php

setcookie('test', time());

ob_start();

print_r($_COOKIE); 

$content = ob_get_contents();

$content = str_replace(" ", '&nbsp;', $content);

ob_clean();

header("content-type:text/html; charset=utf-8");

echo '当前的Cookie为:<br>';

echo nl2br($content);


写回答 关注

2回答

  • 南风丿过境丶
    2019-08-04 17:46:05

    <?php

    setcookie('test', time());

    //创建名为test的cookie,time()设置失效时间

    ob_start();

    //开始进入输出缓冲区

    print_r($_COOKIE); 

    //$_COOKIE变量里面存放所有的cookie,这里的意思是输出所有的cookie

    $content = ob_get_contents();

    //得到缓冲区里面的数据,存放在$content变量里面

    $content = str_replace(" ", '&nbsp;', $content);

    //将数据里面的空格替换为&nbsp的符号

    ob_clean();

    清除缓冲区

    header("content-type:text/html; charset=utf-8");

    //声明文档类型和编码格式

    echo '当前的Cookie为:<br>';

    //输出

    echo nl2br($content);

    //nl2br() 函数在字符串中的每个新行(\n)之前插入 HTML 换行符(<br> 或 <br />)。

  • weibo_雷神伤感_0
    2019-05-31 09:32:56

    1.ob_start — Turn on output buffering

    This function will turn output buffering on. While output buffering is active no output is sent from the script (other than headers), instead the output is stored in an internal buffer.

    The contents of this internal buffer may be copied into a string variable using ob_get_contents(). To output what is stored in the internal buffer, use ob_end_flush(). Alternatively, ob_end_clean() will silently discard the buffer contents.

    2.ob_clean — Clean (erase) the output buffer

    This function discards the contents of the output buffer.

    This function does not destroy the output buffer like ob_end_clean() does.

    The output buffer must be started by ob_start() with PHP_OUTPUT_HANDLER_CLEANABLE flag. Otherwise ob_clean() will not work.

    3.ob_get_contents — Return the contents of the output buffer

    Gets the contents of the output buffer without clearing it.

    以上内容,是在官方文档上查阅~~

    这段代码,看上去像是打开缓冲区;读取cookie,修改;清理缓冲区。

PHP进阶篇

轻松学习PHP中级课程,进行全面了解,用PHP快速开发网站程序

181734 学习 · 2575 问题

查看课程

相似问题