jontynewman/html-filter

用于转换特殊HTML字符的流过滤器。

v1.0 2018-10-31 00:42 UTC

This package is not auto-updated.

Last update: 2024-09-29 10:02:43 UTC


README

用于转换特殊HTML字符的流过滤器。

安装

composer require 'jontynewman/html-filter ^1.0'

示例

<?php

use JontyNewman\HtmlFilter;

require 'vendor/autoload.php';

HtmlFilter::passthru(__FILE__, 'rb');

静态 "passthru" 方法为以下代码提供了一个简写。

<?php

use JontyNewman\HtmlFilter;

require 'vendor/autoload.php';

$handle = HtmlFilter::open(__FILE__, 'rb');

if (false === fpassthru($handle)) {
    throw new RuntimeException('Failed to pass through stream');
}

if (false === fclose($handle)) {
    throw new RuntimeException('Failed to close stream');
}

此外,静态 "open" 方法为以下代码提供了一个简写。

<?php

use JontyNewman\HtmlFilter;

require 'vendor/autoload.php';

HtmlFilter::register();

$handle = fopen(__FILE__, 'rb');

if (false === $handle) {
    throw new RuntimeException('Failed to open stream');
}

if (false === stream_filter_append($handle, HtmlFilter::NAME)) {
    throw new RuntimeException('Failed to append filter');
}

if (false === fpassthru($handle)) {
    throw new RuntimeException('Failed to pass through stream');
}

if (false === fclose($handle)) {
    throw new RuntimeException('Failed to close stream');
}