Skip to content

Instantly share code, notes, and snippets.

@masakielastic
masakielastic / after.php
Created December 8, 2012 15:52
refactored and clarified the logic of checking lead byte and trail bytes
class Escaper
{
public function replaceInvalidByteSequence($str, $substitute = "\xEF\xBF\xBD")
{
$ret = '';
$size = strlen($str);
$pos = 0;

すぐれた PHP ライブラリとリソース

Awesome PHP の記事をフォークして翻訳したものです (2013年4月25日)。おどろくほどすごい PHP ライブラリ、リソースやちょっとした情報のリストです。

【訳者コメント】 PHP 入門者のかたにはクィックリファレンスとして PHP: The Right Way 、セキュリティに関しては2011年3月に出版された 体系的に学ぶ 安全なWebアプリケーションの作り方 をおすすめします。

Composer

@masakielastic
masakielastic / 01_mb_convert_encoding_breaks_well-formed_character.php
Last active July 12, 2017 07:59
mb_convert_encoding breaks well-formed character (PHP 5.5RC3, Mac OSX 10.8).
<?php
// https://en.wikipedia.org/wiki/UTF-8#Examples
// 2-byte character: U+00A2 (CENT SIGN)
mb_substitute_character(0xFFFD);
$data = [
// ill-formed
"\xC2\xA2"."\xC2\xA2"."\xC2",
// ill-formed
@masakielastic
masakielastic / 01_the_result_of_benchmark_for_validating_ascii_characters.txt
Last active December 18, 2015 14:08
Benchmark for validating ascii characters
[ctype]
valid:true
time:4.9642469882965
[byte comparison]
valid:true
time:5.0199990272522
[preg_match]
valid:true
time:5.9788029193878
[mb_check_encoding]
@masakielastic
masakielastic / 01_ctype_lower misditect_non-lower_characters.php
Last active December 18, 2015 18:49
ctype_lower misditect non-lower characters on Mac OSX 10.8.
<?php
$expected = [];
$result = [];
for ($i = 0; $i <= 0xFF; ++$i) {
setlocale(LC_ALL, 'C');
if (ctype_lower(chr($i))) {
$expected[] = $i;
<?php
class TestObject implements JsonSerializable {
public function __construct(array $array) {
$this->array = $array;
}
public function jsonSerialize() {
return $this->array;
@masakielastic
masakielastic / bacon.js_README.md
Last active May 2, 2018 05:07
bacon.js の README の翻訳 (原文は2013年7月1日時点のものを取得)。最新の内容は https://github.com/raimohanska/bacon.js を参照。ライセンスは原文と同じです。

Bacon.js

JavaScript のための小さな FRP (Functional Reactive Programming) ライブラリです。

手続き型から関数型に切り替えることで、イベントスパゲッティのコードがクリーンで宣言スタイルの「風水の bacon」(feng shui bacon)に変わります。入れ子のループを mapfilter のような関数型プログラミングのコンセプトに置き換えることに似ています。個別のイベントに取り組むことを止め、イベントストリームを扱います。mapfilter でデータを変換します。mergecombine でデータを combine します。重火器に切り替え、上司のように flatMapcombineTemplate を掌握します。

このライブラリはイベントのアンダースコア( _ )です。残念なことに ~ の記号は JavaScript では認められていないからです。

資料です。

diff --git a/ext/json/json.c b/ext/json/json.c
index 5360841..1f2ede1 100644
--- a/ext/json/json.c
+++ b/ext/json/json.c
@@ -103,6 +103,8 @@ static PHP_MINIT_FUNCTION(json)
REGISTER_LONG_CONSTANT("JSON_PRETTY_PRINT", PHP_JSON_PRETTY_PRINT, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("JSON_UNESCAPED_UNICODE", PHP_JSON_UNESCAPED_UNICODE, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("JSON_PARTIAL_OUTPUT_ON_ERROR", PHP_JSON_PARTIAL_OUTPUT_ON_ERROR, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("JSON_NOTUTF8_SUBSTITUTE", PHP_JSON_NOTUTF8_SUBSTITUTE, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("JSON_NOTUTF8_IGNORE", PHP_JSON_NOTUTF8_IGNORE, CONST_CS | CONST_PERSISTENT);
diff --git a/ext/json/JSON_parser.c b/ext/json/JSON_parser.c
index dd832a7..3749998 100644
--- a/ext/json/JSON_parser.c
+++ b/ext/json/JSON_parser.c
@@ -353,40 +353,59 @@ use_string:
static void utf16_to_utf8(smart_str *buf, unsigned short utf16)
{
- if (utf16 < 0x80)
- {
Users/masakielastic/.phpbrew/build/php-5.5.4/ext/standard/html.h:58:57: note: passing argument to parameter 'old' here
PHPAPI char *php_escape_html_entities_ex(unsigned char *old, size_t oldlen, size_t *newlen, int all, int flags, char *hint_charset, zend_bool double_encode TSRMLS_DC);