2015年3月15日 星期日
2014年12月25日 星期四
filename extension
var fileName = url.parse(videoReq.fileurl).pathname.split('/').pop().split('.').shift();
//x.avi -> x-360p.mp4
var fileName = $scope.video.path.file.split('.').shift();
var mp4fileName = fileName+"-360p.mp4"
console.log('mp4fileName = '+ mp4fileName);
$scope.video.path.file = mp4fileName;
2014年12月12日 星期五
php exec
php 執行 shell script 並取得返回值:
exec('sh /home/jex_lin/hello.sh', $result, $is_fail);
if ($is_fail)
{
echo "command 發生錯誤";
}
else
{
echo var_dump($result);
}
2014年11月20日 星期四
get user ip
[php] 如何得到使用者的真實ip
How can I get the user's IP address using Node.js?
How can I get the user's IP address using Node.js?
request.connection.remoteAddress
request.connection.remoteAddress2014年11月18日 星期二
CI CodeIgniter
使用CI框架打造RESTful
https://github.com/philsturgeon/codeigniter-restserver
作者還有詳細的說明,請參照他的部落格
Working with RESTful Services in CodeIgniter
作者還有詳細的說明,請參照他的部落格
Working with RESTful Services in CodeIgniter
呼叫檔案exe要注意使用絕對路徑
2014年11月17日 星期一
php debug
.txt
$postArr = array("url"=>$url,"type"=> $type);
$file = 'C:\jacob\debug\log.txt';
$postJSON = json_encode($postArr);
file_put_contents($file, $postJSON);
$this一定要在被new實體化之後才會產生
http://stackoverflow.com/questions/4323411/how-can-i-write-to-console-in-php
$output = "";
echo $output;
2014年7月14日 星期一
php ob_flush
PHP:flush跟ob_flush
class Number {
public $number;
public function __construct() {
$this->number = rand(1,10);!
echo $this->number;
echo "
";
ob_flush(); //output_buffer
flush();
sleep(2);
unset($this); //destruct
}
//recreat object when each time destruct
public function __destruct() {
$number = new Number;
}
}
$number = new Number;
2014年3月25日 星期二
php js
2014年3月13日 星期四
Bootstrap
Bootstrap CDN
15个最好的Bootstrap设计工具推荐
http://vitalets.github.io/x-editable/docs.html
http://kkbruce.tw/
http://kkbruce.tw/
BOOTSTRAP + x-editable + MySQL
$con=mysqli_connect(db('hostname'),db('username'),db('password'),db('dbname'));
//Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$con->query("SET NAMES 'utf8'");
$result = mysqli_query($con,"SELECT * FROM information");
// $query = mysql_query("select * from information");
$i=0;
while($fetch = mysqli_fetch_array($result))
{
if($i%2==0) $class = 'even'; else $class = 'odd';
echo'
'.$fetch['name'].'
'.$fetch['details'].'
'.$fetch['status'].'
';
}
http://crewow.com/PHP-Simple-Update-using-PDO-in-Bootstrap.phpBootstrap datetimepicker
http://www.bootply.com/60789 右鍵檢視原始碼Twitter Bootstrap Tutorial
2014年3月10日 星期一
jQGrid with JSON
http://www.trirand.com/blog/jqgrid/jqgrid.html
jQGrid with JSON Tutorial
book.php JSON
jqGrid获取json数据方法
-- -- 表的结构 `book` -- CREATE TABLE `book` ( `id` int(11) NOT NULL AUTO_INCREMENT, `no` int(11) NOT NULL, `title` varchar(255) NOT NULL, `author` varchar(30) NOT NULL, `publisher` varchar(30) NOT NULL, `year_published` year(4) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
book.php JSON
jqGrid获取json数据方法
{
"page": "1",
"total": "1",
"records": "3",
"rows": [
{
"id": "1",
"cell": [
"22",
"title1",
"author1",
"publisher1",
"2013"
]
},
{
"id": "2",
"cell": [
"25",
"title2",
"author",
"publisher2",
"2014"
]
}
]
}
jQGrid example
2014年3月6日 星期四
jQuery JqGrid
JqGrid—功能強大的jQuery Grid Control
Google 幫目前當紅的 Javascript Framework 都做 Host, 而且透過他的 CDN(Content Delivery Network), 讓全球抓取此 Library 的速度都跟抓當地網站檔案一樣快.
第一個jqGrid範例:Local array
http://trirand.com/blog/jqgrid/jqgrid.html loading Data/ Array Data
$(document).ready(function() {
jQuery("#grid_id").jqGrid({
datatype: "local",
height: 250,
colNames:['Inv No','Date', 'Client', 'Amount','Tax','Total','Notes'],
colModel:[
{name:'id',index:'id', width:60, sorttype:"int"},
{name:'invdate',index:'invdate', width:90, sorttype:"date"},
{name:'name',index:'name', width:100},
{name:'amount',index:'amount', width:80, align:"right",sorttype:"float"},
{name:'tax',index:'tax', width:80, align:"right",sorttype:"float"},
{name:'total',index:'total', width:80,align:"right",sorttype:"float"},
{name:'note',index:'note', width:150, sortable:false}
],
multiselect: true,
caption: "Manipulating Array Data"
}); // jqGrid
var mydata = [
{id:"1",invdate:"2007-10-01",name:"test",note:"note",amount:"200.00",tax:"10.00",total:"210.00"},
{id:"2",invdate:"2007-10-02",name:"test2",note:"note2",amount:"300.00",tax:"20.00",total:"320.00"},
{id:"3",invdate:"2007-09-01",name:"test3",note:"note3",amount:"400.00",tax:"30.00",total:"430.00"},
{id:"4",invdate:"2007-10-04",name:"test",note:"note",amount:"200.00",tax:"10.00",total:"210.00"},
{id:"5",invdate:"2007-10-05",name:"test2",note:"note2",amount:"300.00",tax:"20.00",total:"320.00"},
{id:"6",invdate:"2007-09-06",name:"test3",note:"note3",amount:"400.00",tax:"30.00",total:"430.00"},
{id:"7",invdate:"2007-10-04",name:"test",note:"note",amount:"200.00",tax:"10.00",total:"210.00"},
{id:"8",invdate:"2007-10-03",name:"test2",note:"note2",amount:"300.00",tax:"20.00",total:"320.00"},
{id:"9",invdate:"2007-09-01",name:"test3",note:"note3",amount:"400.00",tax:"30.00",total:"430.00"}
];
for(var i=0;i<=mydata.length;i++)
jQuery("#grid_id").jqGrid('addRowData',i+1,mydata[i]);
});
2014年2月25日 星期二
2014年1月22日 星期三
PHP
PHP isset()和empty()的區別
isset判斷的是 "變數"
empty判斷的是 "值"
http://www.compileonline.com/execute_php_online.php
[PHP]紀錄程式執行時間
function getMicrotime(){
//microtime會回傳微秒及秒(msec sec)
$arr = explode(" ",microtime());
return $arr[0] + $arr[1];
}
//紀錄開始時間
$start = getMicrotime();
$str = "";
for( $i = 0; $i <= 1000000 ; $i++) $str .= "Hello";
//結束時間
$end = getMicrotime();
echo "程式執行了 " . ($end - $start) . "秒 " . (($end - $start) /60 ) . "分";;
?>
How to get file name from full path with PHP?
$file = basename($path); // $file is set to "index.php"
$file = basename($path); // $file is set to "index.php"2014年1月2日 星期四
MySQL Trigger PHP
MySQL Trigger(觸發)
Linux
Windows
Is there any way I can execute a PHP script from MySQL?
Linux
DELIMITER @@
CREATE TRIGGER Test_Trigger
AFTER INSERT ON MyTable
FOR EACH ROW
BEGIN
DECLARE cmd CHAR(255);
DECLARE result int(10);
SET cmd=CONCAT('/usr/bin/php ', '/home/test/beta/demo.php');
SET result = sys_exec(cmd);
END;
@@
DELIMITER ;
Invoking a PHP script from a mysql trigger
Windows
DELIMITER $$
CREATE PROCEDURE udfwrapper_sp
(p1 DOUBLE,
p2 DOUBLE,
p3 BIGINT)
BEGIN
DECLARE cmd CHAR(255);
DECLARE result CHAR(255);
SET cmd = CONCAT('C:/xampp/php/php.exe -f "C:/xampp/htdocs/phpFile.php" ', p1, ' ', p2, ' ', p3);
SET result = sys_eval(cmd);
END$$;
[PHP] 利用 mysqli 建立 MySQL Trigger安裝UDF程式庫 現成MySQL功能輕鬆擴充
2013年12月13日 星期五
MySQL Ajax Table Editor
php/AjaxTableEditor.php
function doQuery($query)
mysql_query("SET NAMES 'UTF8'"); //解決 PHP/mySQL 資料庫讀取中文顯示亂碼或問號
2013年11月21日 星期四
Wordpress and MySQL
UPDATE
$option_tree_value_mysql = 's:5:"title";s:9:"post";s:4:"page";';
$table_name = 'wp_options';
$option_id =100;
$sql = "UPDATE $table_name SET option_value='$option_tree_value_mysql' WHERE option_id=$option_id";
$ereminders = $wpdb->query($wpdb->prepare($sql));
/* 參數測試 */
$wp_user_id =2;
$wp_post_id =1;
$user_blogs_array = get_blogs_of_user( $wp_user_id ); //Notice: 開啓debug模式有 wordpress 3.1前棄用的訊息
foreach ($user_blogs_array AS $user_blog) {
$wp_blog_id = $user_blog->userblog_id;
}
$table_name = 'wp_'.$wp_blog_id.'_postmeta';//'wp_2_options';
$sql = "UPDATE $table_name SET meta_value=%d WHERE meta_key='條件' AND post_id='1'";
$ereminders = $wpdb->query($wpdb->prepare($sql,3));
2013年11月6日 星期三
php mysql utf8
000webhost的資料庫編碼修正(utf-8)
$sql="INSERT INTO ". db('tablename') . " (area_id,name,address, lat, lng) VALUES('$city','$name','$address','$lat','$lng')";
$db_link = mysql_connect(db('hostname'),db('username'),db('password'));
mysql_select_db(db('dbname'), $db_link);
mysql_query("SET NAMES 'utf8'", $db_link);
//$sql="INSERT INTO cafe_map SET name='".$name."'";
mysql_query($sql, $db_link);
echo mysql_error($db_link);
$con=mysqli_connect(db('hostname'),db('username'),db('password'),db('dbname'));
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$con->query("SET NAMES 'utf8'");
$result = mysqli_query($con,"SELECT * FROM ".db('tablename'));
while($row = mysqli_fetch_array($result))
{
$LatLng = "(".$row['lat'].",".$row['lng'].")";
$item_id =$row['id'];
$ScenicName =$row['name'];
$phpecho = $phpecho.$row['id'].$LatLng;
$locations_db_json.='{';
$locations_db_json.= 'latlng : new google.maps.LatLng';
$locations_db_json.= $LatLng;//'(25.0336148,120.56480220000003)';
$locations_db_json.=',';
$locations_db_json.= 'info :';
$locations_db_json.= '"'.$row['id'].":".$ScenicName.'"'; ;//'"hello"'; $markerName
$locations_db_json.= '},';
}
mysqli_close($con);
2013年10月17日 星期四
php generate html
php生成HTML的两种方法、PHP生成静态页的两种方法
$nowtime=time();
$pastsec = $nowtime - $_GET["t"];
if($pastsec<60)
{
exit; //1分钟更新一次,时间可以自己调整
}
$content = file_get_contents('https://google-developers.appspot.com/maps/documentation/javascript/examples/full/map-simple?hl=zh-tw');//也可引用扩展名为PHP的网页
$content=preg_replace("/[\r\n]+/", '', $content ); //是将回车去掉,此段可有可无,如影响使用请去除
$content .= "请注意此行代码不要删除 此为定时生成的必要代码 亳州易天科技 WWW.YISKY.NET PHP自动生成HTML(PHP生成静态面页)实例";
file_put_contents("index.html",$content);
if (!function_exists("file_put_contents"))
{
function file_put_contents($fn,$fs)
{
$fp=fopen($fn,"w+");
fputs($fp,$fs);
fclose($fp);
}
}
2013年10月16日 星期三
php string
$email = 'htshboy@gmail.com';
$domain = explode("@", $email);
echo 'account='.$domain[0]. ' ';
php去掉字符串的最后一个字符附substr()的用法
$str = "1,2,3,4,5,6,"; $newstr = substr($str,0,strlen($str)-1); echo $newstr;原字串1,2,3,4,5,6, 去掉最后一个字符",",最终结果为1,2,3,4,5,6
//假設檔名
$filename = 'mypic.gif';
// 1. 使用陣列函式 "explode/end" 方式
$ext = end(explode('.', $filename));
// 2. 使用字串函式 "strrchr" 方式
$ext = substr(strrchr($filename, '.'), 1);
// 3. 使用字串函式 "strrpos" 方式
$ext = substr($filename, strrpos($filename, '.') + 1);
// 4. 使用正規式 "preg_replace" 方式
$ext = preg_replace('/^.*\.([^.]+)$/D', '$1', $filename);
// 5. 特別(從來沒用過)方式
// 參考: http://php.about.com/od/finishedphp1/qt/file_ext_PHP.htm
$exts = split("[/\\.]", $filename);
$n = count($exts)-1;
$ext = $exts[$n];
訂閱:
文章 (Atom)