PHP_Compat 提供多個 PHP 5 專有函數的相容實作,讓 PHP 4 環境也能使用 file_put_contents、array_combine、str_split 等函數。
pear install PHP_Compat
<?php
require_once 'PHP/Compat.php';
// 載入單一函數
PHP_Compat::loadFunction('file_put_contents');
// 一次載入多個函數
PHP_Compat::loadFunction(array('str_split', 'array_chunk', 'file_get_contents'));
// 現在可直接使用
$arr = str_split('Hello World');
file_put_contents('test.txt', 'Hello');
?>
file_put_contents / file_get_contentsarray_combine / array_chunk / str_splithtmlspecialchars_decode / http_build_queryjson_encode / json_decode(需 PHP 5.2+ 原生,Compat 提供部分實作)