Skip to content

Instantly share code, notes, and snippets.

<html>
<head><title>Hello</title></head>
<body><p>Hello, world!</p></body>
</html>
@msng
msng / email_extended.php
Created November 28, 2011 01:05
Another CakePHP validation rule for email, accepting irregular addresses once allowed by docomo and au
<?php
//For PHP 5.3.x or later
public function emailExtended($data, $deep = false) {
$pattern = '/.+@(docomo|ezweb)\.ne\.jp$/i';
$check = preg_replace_callback($pattern, function($matches) {
$patterns = array('/\.{2,}/', '/\.@/');
$replacements = array('.', '@');
return preg_replace($patterns, $replacements, $matches[0]);
}, array_shift($data));
return Validation::email($check, $deep);
<?php
function mb_strimlen($str, $start, $length, $trimmarker = '', $encoding = false) {
$encoding = $encoding ? $encoding : mb_internal_encoding();
$str = mb_substr($str, $start, mb_strlen($str), $encoding);
if (mb_strlen($str, $encoding) > $length) {
$markerlen = mb_strlen($trimmarker, $encoding);
$str = mb_substr($str, 0, $length - $markerlen, $encoding) . $trimmarker;
}
return $str;
}
@msng
msng / ogp_example.html
Created December 2, 2011 06:47
An example of OGP
<meta property="fb:admins" content="100002501170896" />
<meta property="fb:app_id" content="285724981447786" />
<meta property="og:url" content="http://www.msng.info/" />
<meta property="og:type" content="blog" />
<meta property="og:title" content="頭ん中" />
<meta property="og:locale" content="ja_JP" />
<meta property="og:site_name" content="頭ん中" />
<meta property="og:image" content="http://www.msng.info/wp-content/themes/msng/img/favicon4.png" />
<meta property="og:description" content="インターネットやコミュニケーションの話題を中心に、思ったことをつらつらと書いていくブログです。" />
@msng
msng / ogp.php
Created December 7, 2011 05:38
OGP Helper class file
<?php
/**
* Ogp Helper class file
*
* Adds OGP elements in <head />
*
* Licensed under The MIT License
*
* @author Masunaga Ray (http://www.msng.info/)
* @link http://www.msng.info/archives/2011/12/cakephp-ogp-helper.php
<script type="text/javascript">if (window.top != window.self) window.top.location = window.self.location;</script>
@msng
msng / number_unformat.php
Created December 21, 2011 02:07
Unformats a number formatted with number_format().
<?php
function number_unformat($number, $force_number = true, $dec_point = '.', $thousands_sep = ',') {
if ($force_number) {
$number = preg_replace('/^[^\d]+/', '', $number);
} else if (preg_match('/^[^\d]+/', $number)) {
return false;
}
$type = (strpos($number, $dec_point) === false) ? 'int' : 'float';
$number = str_replace(array($dec_point, $thousands_sep), array('.', ''), $number);
settype($number, $type);
@msng
msng / gist:1736439
Created February 4, 2012 08:45
WordPress の個別記事にはてブと Google+ と Twitter と Facebook「いいね!」のボタンを出すサンプル
<!--
・できれば <body> タグの直後に置く
・日本語ボタンを出すなら en_US を ja_JP にする
・アプリケーションIDをつける場合は、xfbml=1 の後に
&appId=[Facebookで取得するアプリケーションID: https://developers.facebook.com/apps ]
をつける
-->
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
@msng
msng / is_hankaku.php
Created March 23, 2012 05:34
文字列が半角のみでできているかどうかチェックするのもうこれでいいんじゃないの
<?php
function is_hankaku($str, $include_kana = false, $include_controls = false, $encoding = null) {
if (!$include_controls && !ctype_print($str)) {
return false;
}
if (is_null($encoding)) {
$encoding = mb_internal_encoding();
}
if ($include_kana) {
@msng
msng / is_zenkaku.php
Created March 23, 2012 11:25
全角のみのチェックもうこれでいいんじゃないの
<?php
//Requires function is_hankaku() https://gist.github.com/2167287
function is_zenkaku($str, $encoding = null) {
if (is_null($encoding)) {
$encoding = mb_internal_encoding();
}
$len = mb_strlen($str, $encoding);
for ($i = 0; $i < $len; $i++) {
$char = mb_substr($str, $i, 1, $encoding);
if (is_hankaku($char, true, true, $encoding)) {