Skip to content

Instantly share code, notes, and snippets.

<script type="text/javascript">if (window.top != window.self) window.top.location = window.self.location;</script>
@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
@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="インターネットやコミュニケーションの話題を中心に、思ったことをつらつらと書いていくブログです。" />
<?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 / 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);
<html>
<head><title>Hello</title></head>
<body><p>Hello, world!</p></body>
</html>