Skip to content

Instantly share code, notes, and snippets.

@chocomelonchan
Last active January 1, 2016 04:29
Show Gist options
  • Save chocomelonchan/8092521 to your computer and use it in GitHub Desktop.
Save chocomelonchan/8092521 to your computer and use it in GitHub Desktop.
⑨クラス
<?php
/**
* あたいったら最強ね!!(神クラス)
* @author cirno
*/
class Utilno {
/**
* チルノがクライアントのエージェントがモバイルならtrueを返してくれる
* @return モバイルならtrue、そうでなければfalse
*/
public static function isMobile () {
$devices = array(
'iPhone', // Apple iPhone
'iPod', // Apple iPod touch
'Android', // 1.5+ Android
'dream', // Pre 1.5 Android
'CUPCAKE', // 1.5+ Android
'blackberry9500', // Storm
'blackberry9530', // Storm
'blackberry9520', // Storm v2
'blackberry9550', // Storm v2
'blackberry9800', // Torch
'webOS', // Palm Pre Experimental
'incognito', // Other iPhone browser
'webmate' // Other iPhone browser
);
$user_agent = $_SERVER['HTTP_USER_AGENT'];
foreach ($devices as $device) {
if (stripos($user_agent, $device) !== false) {
return true;
}
}
return false;
}
/**
* urlの内容を読み込む
*
* @param string $url 読み込み先URL
* @return string 読み込んだ内容
*/
public static function read($url)
{
$ifp = fopen($url, 'r');
if ($ifp == false) {
return false;
}
$response = '';
while (!feof($ifp)) {
$response .= fgets($ifp);
}
fclose($ifp);
return $response;
}
/**
* $pathのファイルに$strの内容を書き込む
*
* @param string $path 書き込む先ファイル
* @param string $str 書き込む内容
*/
public static function write($url, $str)
{
$ofp = fopen($url, 'w');
if ($ofp == false) {
return;
}
$response = '';
fwrite($ofp, $str);
fclose($ofp);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment