<?php
/**
* 判斷是否 ajax 請求
* [@return](https://learnku.com/users/31554) bool
*/
function isAjax()
{
return isset($_SERVER['HTTP_X_REQUESTED_WITH']) && ('xmlhttprequest' == strtolower($_SERVER['HTTP_X_REQUESTED_WITH']));
}
/**
* 獲取請求引數
* @param $param
* @param string $method
* @param string $default
* [@return](https://learnku.com/users/31554) string
* @date 2017-07-27
*/
function input($param, $method = 'all', $default = '')
{
$method = strtolower($method);
$method = in_array($method, array('get', 'post', 'all')) ? $method : 'all';
switch ($method) {
case 'get' :
$params = $_GET;
break;
case 'post' :
$params = $_POST;
break;
default :
$params = array_merge($_GET, $_POST);
break;
}
$ret = isset($params[$param]) ? $params[$param] : $default;
return stripslashes($ret);
}
// 獲取不為空的 p 標籤的值,並且在 200 字以內
private function get_first_p($content)
{
preg_match_all("/<p[^>]*>(?:(?!<\/p>)[\s\S])*<\/p>/",$content,$matchs);
foreach($matchs[0] as $match){
$match = preg_replace("#<[^>]+>#","$2",$match);
$match = trim($match);
if(!empty($match))
{
return mb_substr($match,0,200);
}
}
return "";
}
本作品採用《CC 協議》,轉載必須註明作者和本文連結