PHP
XOOPS 寫模組有個問題….
假設模組需要用到 Jquery檔案,要載入
一般寫在 HEADER 下面就行了
$xoopsTpl->assign("xoops_module_header", '');但是,XOOPS也是有佈景檔的,當佈景檔已經載入 JQUERY.JS 這時候就會發生小小衝突
寫了一個 函式,由PHP 判斷 ‘jquery/jquery.js’ 這隻程式是否被載入
PHP
if(!function_exists('json_decode')){
include("json.php");
$json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
function json_decode($arr){
global $json;
return $json->decode($arr);
}
function json_encode($arr){
global $json;
return $json->encodeUnsafe($arr);
}
}JSON Class 的名稱為 Services_JSON
* @category * @package Services_JSON * @author Michal Migurski <mike-json@teczno.com> * @author Matt Knapp <mdknapp[at]gmail[dot]com> * @author Brett Stimmerman <brettstimmerman[at]gmail[dot]com> * @copyright 2005 Michal Migurski * @version CVS: $Id: JSON.php,v 1.31 2006/06/28 05:54:17 migurski Exp $ * @license http://www.opensource.org/licenses/bsd-license.php * @link http://pear.php.net/pepr/pepr-proposal-show.php?id=198
下載 function ,google 搜尋到的 修正 IE 中文檔名會錯誤的問題
使用用法,檔名可不加,不加即為路徑檔名
dl_file("路徑","檔名")function dl_file($file,$fname=""){
//First, see if the file exists
if (!is_file($file)) { die("<strong>404 File not found!</strong>"); }
//Gather relevent info about file
$filename = ($fname)? $fname:basename($file);
if(strpos($_SERVER['HTTP_USER_AGENT'] ,"MSIE")){
$filename = urlencode ($filename);
}
//Gather relevent info about file
$len = filesize($file);
$file_extension = strtolower(getExtension($file));
//This will set the Content-Type to the appropriate setting for the file
switch( $file_extension ) {
case "pdf": $ctype="application/pdf"; break;
case "exe": $ctype="application/octet-stream"; break;
case "zip": $ctype="application/zip"; break;
case "doc": $ctype="application/msword"; break;
case "xls": $ctype="application/vnd.ms-excel"; break;
case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
case "gif": $ctype="image/gif"; break;
case "png": $ctype="image/png"; break;
case "jpeg":
case "jpg": $ctype="image/jpg"; break;
case "mp3": $ctype="audio/mpeg"; break;
case "wav": $ctype="audio/x-wav"; break;
case "mpeg":
case "mpg":
case "mpe": $ctype="video/mpeg"; break;
case "mov": $ctype="video/quicktime"; break;
case "avi": $ctype="video/x-msvideo"; break;
//The following are for extensions that shouldn't be downloaded (sensitive stuff, like php files)
case "php":
case "htm":
case "html":
case "txt": $ctype="application/octet-stream"; break;
default: $ctype="application/force-download";
}
//Use the switch-generated Content-Type
//Force the download
header('Pragma: public');
header('Expires: 0');
header('Last-Modified: ' . gmdate('D, d M Y H:i ') . ' GMT');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header("Cache-Control: public");
header("Content-Type: $ctype");
header("Content-Description: File Transfer");
header('Content-Disposition: attachment; Filename="'.$filename.'"');
header('Content-Transfer-Encoding: binary');
header("Content-Length: ".$len);
@readfile($file);
exit;
}PHP 有個說明文件非常方便,想查什麼函式只要記得一點點就可以查找出來
前兩天我用了 逐行讀入的 程式,查找的是 file()
程式如下
$lines = file('http://www.example.com/');
// Loop through our array, show HTML source as HTML source; and line numbers too.
foreach ($lines as $line_num => $line) {
echo "Line #{$line_num} : " . htmlspecialchars($line) . "
";
}但是讀出了之後,我想把換行刪除掉卻一直也刪不掉….
用了 str_replace() 取代 “\n”,卻一直無法取代
還用了 n2br,也無法取代掉…..
