本文目錄一覽:
本人零基礎 想學習寫一個最簡單的php程序 hello world但不知道怎樣從網上下載和安裝並寫出來?
先學PHP基礎,再去百度查自己需要的功能的原理,然後去實驗,實驗成功後在網站上使用它。
走完這四步,你才算學會了這門技術的一個功能。
學不會PHP人絕大部分一直在重複第一步 !
w3school上的教程非常的基礎,很容易懂,建議先看完它。然後可以看看php100的視頻教程,這個講得很細很易懂,而且講知識點非常的多,我也是看這個學會的。
還是那句話,看教程只是在背乘法口訣,只會乘法口訣的學生從來都不會做應用題,只有使用它,那才是真正的學習!
如何編寫一個PHP的C擴展
一、首先下載PHP源碼包,假設源碼包目錄為:/software/php-5.2.13
一、首先下載PHP源碼包,假設源碼包目錄為:/software/php-5.2.13
# cd /software/php-5.2.13/ext
二、假設我們要開發一個名為caleng_module的擴展,該擴展包含兩個函數:a–處理兩個整型相加和b-處理字符串重複輸出;
1、首先編寫一個函數定義文件,該文件編寫函數原型後綴為def,假設為:caleng_module.def
int a(int x, int y)
string b(string str, int n)
2、通過擴展骨架生成器,將在ext目錄下自動建立擴展目錄caleng_module
# ./ext_skel –extname=caleng_module –proto=caleng_module.def
3、修改配置文件: # vim /software/php-5.2.13/ext/caleng_module/config.m4,將如下行的注釋標籤”dnl”去掉,修改後如下所示:
PHP_ARG_ENABLE(myfunctions, whether to enable myfunctions support,
Make sure that the comment is aligned:
[ –enable-myfunctions Enable myfunctions support])
4、完善函數a和b的功能: # vim /software/php-5.2.13/ext/caleng_module/caleng_module.c
PHP_FUNCTION(a)
{
int x, y, z;
int argc = ZEND_NUM_ARGS();
if (zend_parse_parameters(argc TSRMLS_CC, “ll”, x, y) == FAILURE)
return;
z = x + y;
RETURN_LONG(z);
}
PHP_FUNCTION(b)
{
char *str = NULL;
int argc = ZEND_NUM_ARGS();
int str_len;
long n;
char *result;
char *ptr;
int result_length;
if (zend_parse_parameters(argc TSRMLS_CC, “sl”, str, str_len, n) == FAILURE)
return;
result_length = str_len * n;
result = (char *) emalloc(result_length + 1);
ptr = result;
while (n–) {
memcpy(ptr, str, str_len);
ptr += str_len;
}
*ptr = ‘\0’;
RETURN_STRINGL(result, result_length, 0);
}
三、編譯安裝,假設php的安裝目錄為:/usr/localhost/webserver/php
# cd /software/php-5.2.13/ext/caleng_module
# /usr/localhost/webserver/php/bin/phpize
# ./configure –with-php-config=/usr/localhost/webserver/php/bin/php-config
# make
# make install
現在將在/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20060613目錄下生成caleng_module.so文件
在php.ini配置文件中加入: extension=caleng_module.so.
搞定收工
如何使用 PHP 輸出“hello world”
1、開啟本地服務器。
2、php代碼編寫,輸出信息。
3、把文件放到本地服務器,www目錄下。
4、打開瀏覽器測試php代碼。
5、在瀏覽器輸入本地服務器地址:localhost.
6、測試成功,則在瀏覽器顯示輸出:hello-word
7、顯示成功
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/183876.html