PHP的原生操作

PHP原生操作的使用
1、PHP读取文件
// 打开文件
$file = fopen("zh.html", "r+") or die("unable to open file");
// 读取文件
$content = fread($file, filesize("zh.html"));
// 打印文件
print_r($content);
// 关闭文件
fclose($file);
2、PHP写入文件
$file = fopen("z.html", "a") or die("读取文件失败");
$insert = "<meta charset='utf8'>\n<h1>这是一段HTML代码</h1>\r\n";
fwrite($file, $insert);
fwrite($file, "<title>我是一个标题</title>");
fclose($file);
3、PHP读取表单
$p = $_REQUEST;
$e = $_ENV;
print_r($p);
sleep(3);
header("Location: zh.html");	// PHP的跳转
4、PHP原生的渲染页面以及页面传值
class Base
{
    // 存key
    public $key;

    // 存value
    public $value;

    // 存数据
    public $array;

    public function assign($key, $value)
    {
        if (is_array($value)) {
            $this->array["$key"] = $value;
        }else{
            $this->array["$key"] = compact("$value");
        }
    }

    public function display($tpl)
    {
        $this->assign($this->key, $this->value);
        extract($this->array);
        if (file_exists($tpl)) {
            include $tpl;
        }
    }
}

class IndexController extends Base {
    public function index($tpl, $data = [])
    {
        $this->assign("data", $data);
        $this->display($tpl);
    }
}

$i = new IndexController();

$i->index("zh.html", ["index" => $_REQUEST]);

HTML部分


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<script src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script>
<body>
<h1>你好</h1>
<?php var_dump($data) ?>
<button onclick="test()">单机</button>
</body>
<script>
    /*$.getJSON("https://novel-cn.oss-cn-shanghai.aliyuncs.com/content/839f6cbf56b76a1bd8b29e60/0828f909d0d1d8778cd8f6e2", function (res) {
        console.log(res)
    })*/
    function test() {
        console.log(11)
        $.ajax({
            type: "get",
            url: "https://novel-cn.oss-cn-shanghai.aliyuncs.com/content/839f6cbf56b76a1bd8b29e60/0828f909d0d1d8778cd8f6e2",
            dataType: "jsonp",
            success: function () {
                console.log(111)
            }
        });
    }
</script>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值