Php常見問題總結(jié)(2)_PHP教程
教程Tag:暫無Tag,歡迎添加,賺取U幣!
推薦:使用Xdebug優(yōu)化你的php程序我本地使用的是xampp服務(wù)器套件,版本是1.64,發(fā)現(xiàn)里面代的php_xdebug.dll竟然無法使用.應(yīng)該是xdebug版本和當(dāng)前的php版本(5.24)版本不符合。去下載了相應(yīng)的版本發(fā)現(xiàn)可以正常工作了。在php.ini里
4:為什么我向另一網(wǎng)頁傳送變量時(shí),只得到前半部分,以空格開頭的則全部丟失
| <?php $Var="hello php";//修改為$Var=" hello php";試試得到什么結(jié)果 $post= "receive.php?Name=".$Var; header("location:$post"); ?> |
receive.php的內(nèi)容:
| <?PHP Echo "<pre>"; Echo $_GET["Name"]; Echo "</pre>"; ?> |
正確的方法是
| <?php $Var="hello php"; $post= "receive.php?Name=".urlencode($Var); header("location:$post"); ?> |
在接收頁面你不需要使用Urldecode(),變量會(huì)自動(dòng)編碼.
5:如何截取指定長(zhǎng)度漢字而不會(huì)出現(xiàn)以"?>"結(jié)尾,超出部分以"..."代替
一般來說,要截取的變量來自Mysql,首先要保證那個(gè)字段長(zhǎng)度要足夠長(zhǎng),一般為char(200),可以保持100個(gè)漢字,包括標(biāo)點(diǎn).
| <?PHP $str="這個(gè)字符好長(zhǎng)呀,^_^"; $Short_Str=showShort($str,4);//截取前面4個(gè)漢字,結(jié)果為:這個(gè)字符... Echo "$Short_Str"; Function csubstr($str,$start,$len) { $strlen=strlen($str); $clen=0; for($i=0;$i<$strlen;$i ,$clen ) { if ($clen>=$start $len) break; if(ord(substr($str,$i,1))>0xa0) { if ($clen>=$start) $tmpstr.=substr($str,$i,2); $i ; } else { if ($clen>=$start) $tmpstr.=substr($str,$i,1); } } return $tmpstr; } Function showShort($str,$len) { $tempstr = csubstr($str,0,$len); if ($str<>$tempstr) $tempstr .= "..."; //要以什么結(jié)尾,修改這里就可以. return $tempstr; } |
分享:php4和php5單態(tài)模式(Singleton Pattern)寫法單態(tài)模式(Singleton Pattern) 就是一個(gè)類Class只有一個(gè)實(shí)例存在。(Ensure a class only has one instance, and provide a global point of access to it.)
這個(gè)是php5的寫法。
相關(guān)PHP教程:
- PHPNOW安裝Memcached擴(kuò)展方法詳解
- php記錄頁面代碼執(zhí)行時(shí)間
- PHP中獎(jiǎng)概率的抽獎(jiǎng)算法程序代碼
- apache設(shè)置靜態(tài)文件緩存方法介紹
- php對(duì)圖像的各種處理函數(shù)代碼小結(jié)
- PHP 關(guān)于訪問控制的和運(yùn)算符優(yōu)先級(jí)介紹
- 關(guān)于PHP語言構(gòu)造器介紹
- php/js獲取客戶端mac地址的實(shí)現(xiàn)代碼
- php5.5新數(shù)組函數(shù)array_column使用
- PHP preg_match的匹配多國(guó)語言的技巧
- php 中序列化和json使用介紹
- php采集文章中的圖片獲取替換到本地
PHP教程Rss訂閱編程教程搜索
PHP教程推薦
- 服務(wù)器變量 $_SERVER 的深入解析
- PHP register_shutdown_function函數(shù)的深入解析
- php判斷終端是手機(jī)還是電腦訪問網(wǎng)站代碼
- 十天學(xué)會(huì)php之第七天
- PHP正則匹配中文字母數(shù)字正則表達(dá)式
- 解析php根據(jù)ip查詢所在地區(qū)
- php正則表達(dá)式使用的詳細(xì)介紹
- 解析PHP初學(xué)者14個(gè)典型疑難問題
- PHP實(shí)現(xiàn)任意字符集下正常顯示網(wǎng)頁的方法
- 淺析動(dòng)態(tài)網(wǎng)頁技術(shù)PHP中錯(cuò)誤處理的一些方法
- 相關(guān)鏈接:
- 教程說明:
PHP教程-Php常見問題總結(jié)(2)
。