Skip to content

Instantly share code, notes, and snippets.

View fetus-hina's full-sized avatar
💭
I may be slow to respond.

AIZAWA Hina fetus-hina

💭
I may be slow to respond.
View GitHub Profile
@fetus-hina
fetus-hina / mb_explode.function.php
Created February 20, 2012 07:00
mb_explode() function
<?php
/*
* Copyright (C) 2012 by HiNa <[email protected]>. All rights reserved.
*
* LICENSE
*
* This source file is subject to the 2-clause BSD License(Simplified
* BSD License).
*/
if(!function_exists('mb_explode')) {
@fetus-hina
fetus-hina / grid_locator.php
Created December 25, 2011 06:32
Grid Locator 計算
<?php
$latitude = 35.675889;
$longitude = 139.744972;
var_dump(calcGL($latitude, $longitude)); // string(6) "PM95UQ"
function calcGL($latitude, $longitude) {
$core_function =
function ($gl_ll) {
$field = (int)floor($gl_ll);
@fetus-hina
fetus-hina / gist:1404506
Created November 29, 2011 11:34
mb_str_replace() 説明ページ用 str_replace エミュレート例
<?php
$subject = 'hogefuga';
$table = array('hoge' => 'foo',
'fuga' => 'bar',
'piyo' => 'baz',
'foo' => '***',
'bar' => '+++',
'baz' => '---');
// mb_str_replace の置き換え動作
@fetus-hina
fetus-hina / output.txt
Created November 29, 2011 11:22
mb_str_replace() 説明ページ用互換性注意事項
<?php
$subject = 'hogefuga';
$table = array('hoge' => 'foo',
'fuga' => 'bar',
'piyo' => 'baz',
'foo' => '***',
'bar' => '+++',
'baz' => '---');
$functions = array('str_replace', 'mb_str_replace');
foreach($functions as $f) {
@fetus-hina
fetus-hina / mb_str_replace.function.php
Created November 29, 2011 11:18
mb_str_replace() 説明ページ表示用ソース(リリースソース)
<?php
/*
* マルチバイト対応 str_replace()
*
* Release 3 update 1
*
* Copyright (C) 2006,2007,2011,2012 by HiNa <[email protected]>. All rights reserved.
*
* LICENSE
*
@fetus-hina
fetus-hina / gist:1404449
Created November 29, 2011 11:14
mb_str_replace() 説明ページ用使い方例
<?php
require_once(dirname(__FILE__) . '/mb_str_replace.function.php');
$subject = '赤パジャマ青パジャマ黄パジャマ';
$search = 'パジャマ';
$replace = '信号';
$result = mb_str_replace($search, $replace, $subject);
var_dump($result);
@fetus-hina
fetus-hina / gist:1404444
Created November 29, 2011 11:12
mb_str_replace() 説明ページ用プロトタイプ
<?php
/**
* マルチバイト対応 str_replace
*
* @param mixed $search 検索文字列
* @param mixed $replace 置換文字列
* @param mixed $subject 対象文字列
* @param string $encoding 文字列のエンコーディング(省略: 内部エンコーディング)
*
* @return mixed subject 内の search を replace で置き換えた文字列
<?php
class Text_Ngram implements Countable, SeekableIterator, ArrayAccess {
private
$text = '',
$chunk_size = 0,
$max_count = 0,
$charset = 'UTF-8',
$current = 0; // for iterator
public function __construct($text, $n, $charset = 'AUTO') {
@fetus-hina
fetus-hina / gist:1199879
Created September 7, 2011 05:54
FC2 他 metaWeblog API 対応ブログ用 API 投稿サンプル
<?php
date_default_timezone_set('Asia/Tokyo');
require_once('Zend/XmlRpc/Client.php');
require_once('Zend/Date.php');
define('BLOG_ID', '0'); // 何でもOK?
define('USERNAME', '********');
define('PASSWORD', '********');
$client = new Zend_XmlRpc_Client('http://blog.fc2.com/xmlrpc.php');
@fetus-hina
fetus-hina / gist:1195111
Created September 5, 2011 14:26
Zend_Service_Twitter を PHP 5.1 で動かすための無理矢理な動作変更継承
<?php
class Xend_Service_Twitter extends Zend_Service_Twitter {
protected function _prepare($path) {
try {
parent::_prepare($path);
} catch(Zend_Uri_Exception $e) {
$this->_localHttpClient->resetParameters()->setUri($this->_uri->__toString());
}
}
}