目前分類:php (18)

瀏覽方式: 標題列表 簡短摘要

解決 PHP/mySQL 資料庫讀取中文顯示亂碼或問號

Felix 發表在 痞客邦 PIXNET 留言(0) 人氣()

 開發一個web項目,通常分為兩部分,一部分是GUI,即界面、美工,使用HTML,CSS,JS編寫,另一部分則是業務邏輯,即程序、功能,使用PHP編寫。而模板引擎則是聯繫這兩部分的「橋樑」,可理解成一個PHP類,裡面定義了許多方法,實現了將PHP的原始輸出加載上界面樣式後再輸出。

 

    沒用模板之前的編寫的代碼是這樣的:

Felix 發表在 痞客邦 PIXNET 留言(0) 人氣()

<?php
$content = "";
$fp = fopen("http://file-to-download.com/a-file.zip", "rb");

if (!$fp)
die("Error opening file.");
while (!feof($fp))
$content .= fread($fp, 2048);
fclose($fp);

$fp=fopen("local-file-name.zip", "w");
fwrite($fp, $content);
fclose($fp);
?>

Felix 發表在 痞客邦 PIXNET 留言(0) 人氣()

首先要講下 at 命令 是要用 /bin/bash shell 來執行的,
你可以在php裡查一下 apache 使用的是哪個 shell,
<?

$output = shell_exec('echo $SHELL');

Felix 發表在 痞客邦 PIXNET 留言(0) 人氣()

 

This is because images and tmp_file_upload are only writable by root user. For upload to work we need to make the owner of those folders same as httpd process owner OR make them globally writable (bad practice).

  1. Check apache process owner:  ps aux | grep httpd. The first column will be the owner typically it will be nobody
  2. Change the owner of images and tmp_file_upload to be become nobody or whatever the owner you found in step 1.

    $sudo chown nobody /var/www/html/mysite/images/

Felix 發表在 痞客邦 PIXNET 留言(0) 人氣()

上傳多個檔案

可以對 input 功能變數使用不同的 name 來上傳多個檔案。

PHP 支援同時上傳多個檔案並將它們的訊息自動以陣列的形式組織。要完成這項功能,需要在 HTML 表單中對檔案上傳功能變數使用和多選框與復選框相同的陣列式送出語法。

注: 對多檔案上傳的支援是在 PHP 3.0.10 版本增加的。

Felix 發表在 痞客邦 PIXNET 留言(0) 人氣()

一開始這樣寫,但出問題

function trim_dom_node($string){
$string=str_replace(" <","<",$string,$count);

Felix 發表在 痞客邦 PIXNET 留言(0) 人氣()

<?

header("Content-Type:text/xml");

echo "<

Felix 發表在 痞客邦 PIXNET 留言(0) 人氣()

In the early days of PHP programming, PHP code was limited to being procedural in nature. Procedural codeis characterized by the use of procedures for the building blocks of the application. Procedures offer a certain level of reuse by allowing procedures to be called by other procedures.

However, without object-oriented language constructs, a programmer can still introduce OO characteristics into PHP code. It's a tad more difficult and can make the code more difficult to read because it's mixing paradigms (procedural language with pseudo-OO design). OO constructs in PHP code — such as the ability to define and use classes, the ability to build relationships between classes that use inheritance, and the ability to define interfaces — make it much easier to build code that adheres to good OO practices.

While purely procedural designs without much modularity run just fine, the advantages of OO design show up in the maintenance. Because a typical application will spend the bulk of its lifetime in maintenance, code maintenance is a large expense over the lifetime of an application. It can also be easily forgotten during development. If you're in a race to get your application developed and deployed, long-term maintainability can take a back seat to getting something to work.

Felix 發表在 痞客邦 PIXNET 留言(0) 人氣()

<?php function foo() {
$numargs = func_num_args(); if ($numargs > 2) {
echo "First: ". func_get_arg(0). "\n";
echo "Second: ". func_get_arg(1). "\n";
echo "Third: ". func_get_arg(2). "\n";
} return $numargs;
}
$n = foo (10, 15, 20); //傳入 3 個參數 echo $n; ?>

Felix 發表在 痞客邦 PIXNET 留言(0) 人氣()

PHP 5.4 支持 單引號 轉換 htmlspecialchars htmlentities 

 

var_dump(get_html_translation_table(HTML_ENTITIES, ENT_QUOTES | ENT_XML1));
, , ,

Felix 發表在 痞客邦 PIXNET 留言(0) 人氣()

HTTP redirects usually have the response status 301 or 302 and provide the redirection URL in the “Location” header. I’ve written three complementary PHP functions that you can use to find out where an URL redirects to (based on a helpful thread at WebmasterWorld). You don’t even need CURL for this – fsockopen() will do just fine.

The PHP script

/**
* get_redirect_url()

Felix 發表在 痞客邦 PIXNET 留言(0) 人氣()

 Pear、Pecl都是PHP擴展模塊的集合。擴展PHP有兩種方法:

  一種是用純粹的PHP代碼寫函數和類。

  Pear就是這樣一個項目。PEAR是PHP的官方開源類庫(PHP Extension and Application Repository的縮寫)。Pear在英文中是梨子的意思。PEAR將PHP程序開發過程中常用的功能編寫成類庫,涵蓋了頁面呈面、數據庫訪問、文件操作、數據結構、緩存操作、網絡協議等許多方面,用戶可以很方便地使用。它是一個PHP擴展及應用的一個代碼倉庫,簡單地說,PEAR就是PHP的cpan。其主頁是pear.php.net。

Felix 發表在 痞客邦 PIXNET 留言(0) 人氣()

一樣是因為工作需要,必須模擬使用者透過Browser去爬固定幾個有問題的網頁來測試,本來在php上面只需要透過fopen()這個函式來抓取網頁即可,如以下方式:

Felix 發表在 痞客邦 PIXNET 留言(0) 人氣()

大部份的網頁空間不能用首兩種方法,第三種比較有機會..

  1. php.ini

    Open the php.ini file and change memory_limit = 8M to a larger value:
    memory_limit = 16M

Felix 發表在 痞客邦 PIXNET 留言(0) 人氣()

Fatal error: Maximum execution time of 30 seconds exceeded
出現這個錯誤如何解決 去哪裡可以設置最大執行時間
辦法:

Felix 發表在 痞客邦 PIXNET 留言(3) 人氣()

請參考 http://simplehtmldom.sourceforge.net/
php Simple HTML DOM Parser 強力解析html 工具


Felix 發表在 痞客邦 PIXNET 留言(6) 人氣()

[From: http://www.phpchina.com/html/20/12020-16121.html]

require()

require() is identical to include() except upon failure it will produce a fatal E_ERROR level error. In other words, it will halt the script whereas include() only emits a warning (E_WARNING) which allows the script to continue.


Felix 發表在 痞客邦 PIXNET 留言(1) 人氣()