19. PHP将网址字符串转换成超级链接该函数将 URL 和 E-mail 地址字符串转换为可点击的超级链接。function makeClickableLinks($text) {
$text = eregi_replace(‘(((f|ht){1}tp://)[-a-zA-Z0-9@:%_+.~#?&//=]+)',
'<a href=“”></a>', $text);
$text = eregi_replace(’([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_+.~#?&//=]+)‘,
'<a href=“http://”></a>', $text);
$text = eregi_replace(’([_.0-9a-z-]+@([0-9a-z][0-9a-z-]+.)+[a-z]{2,3})‘,
'<a href=“mailto:”></a>', $text); return $text;
}20. PHP调整图像尺寸创建图像缩略图需要许多时间,此代码将有助于了解缩略图的逻辑。/**********************
*@filename - path to the image
*@tmpname - temporary path to thumbnail
*@xmax - max width
*@ymax - max height
*/
function resize_image($filename, $tmpname, $xmax, $ymax)
{
$ext = explode(“.”, $filename);
$ext = $ext[count($ext)-1]; if($ext == “jpg” || $ext == “jpeg”)
$im = imagecreatefromjpeg($tmpname);
elseif($ext == “png”)
$im = imagecreatefrompng($tmpname);
elseif($ext == “gif”)
$im = imagecreatefromgif($tmpname); $x = imagesx($im);
$y = imagesy($im); if($x <= $xmax && $y <= $ymax)
return $im; if($x >= $y) {
$newx = $xmax;
$newy = $newx * $y / $x;
}
else {
$newy = $ymax;
$newx = $x / $y * $newy;
} $im2 = imagecreatetruecolor($newx, $newy);
imagecopyresized($im2, $im, 0, 0, 0, 0, floor($newx), floor($newy), $x, $y);
return $im2;
}21. PHP检测 ajax 请求大多数的 JavaScript 框架如 jquery,Mootools 等,在发出 Ajax 请求时,都会发送额外的 HTTP_X_REQUESTED_WITH 头部信息,头当他们一个ajax请求,因此你可以在服务器端侦测到 Ajax 请求。if(!emptyempty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest’){
//If AJAX Request Then
}else{
//something else
}
本篇文章是有青岛达内培训为您呈现,希望给您带来更多更好的文章