Ⅰ php 里怎麼寫自己的方法。在線急等
echo '<script language="JavaScript">function test(){
//.....這樣嗎?
}</script>'
Ⅱ php類怎麼寫
<?php
class ClassName {
public $name = 'ClassName'
protected $_version = Ƈ.0'
private $_author = 'incNick'
public function a(){}
protected function _b() {}
private function _c() {}
}
class Children extends ClassName {
}
var是php4中的用法,相當於public,php4中不支持protected等
public關鍵字:公共訪問的屬性、方法
protected關鍵字:類及子類內公共訪問的屬性、方法
private關鍵字:當前類內私有的屬性、方法
final關鍵字:最終的,子類中不允許覆蓋。如果是finalclass,該類不可被繼承。
static關鍵字:靜態屬性、方法,如publicstatic$abc
const關鍵字:常量屬性,如constABC='test'
更多個解釋看手冊吧親,實在太多了
Ⅲ PHP文件寫入的幾種方法
通過fwrite
$file = fopen("test.txt","a+"); //次方法會自動生成文件test,txt,a表示追加寫入,
//w代表替換寫入 fwrite($file,"寫入代碼"); fclose($file);
file_put_content()方法寫入
file_put_contents("test.txt","奧斯卡老\r\n頓積分");//這里說一下\r\n在雙引號下
//才會換行如果單引號就識別不了
//如果想追加寫入內容,這個函數還有第三個參數FILE_APPEND
Ⅳ phpstorm怎麼寫php代碼
工具原料:phpStorm+wapmserver+計算機
配置php和寫php代碼方法如下:
Ⅳ php 函數怎麼寫好 寫類裡面好還是直接寫頁面里好
如果函數經常用的話,就寫在類裡面,如果只在頁面上載入,其它地方不調用,那就寫在頁里。 這樣寫的話,可以加快程序反應速度
Ⅵ PHP中這種方法怎樣寫的
這是類對象調用,比如有下面一個類
class yi{
public $a = 0; //這里設置一個共有變數,並賦值為0
public function diyi($b = 0){ //這里設置一個共有函數方法,並提供一個差數
$this -> a += $b; //這里將上面的那個共有變數的值加上這個函數方法的參數
return $this;//向函數方法返回當前對象
}
public function show(){
echo $this -> a;//這里輸出上面的那個公共變數
}
}
然後使用這個類的時候就是這樣調用
$yi = new yi;實例化這個類,格式是 變數 = new 類名稱
$yi -> diyi(50) -> show(); //這里是調用類中的函數方法diyi並提供一個參數50,接著繼續調用類中的函數方法 show,那麼,這段代碼運行後的最後結果就是 50
這樣說,你應該明白了吧?
Ⅶ PHP網路編程的代碼怎麼寫
PHP網路編程的代碼怎麼寫?本篇文章給大家介紹的是關於PHP網路編程的代碼,有興趣的朋友可以看一下
//echo gethostbyname("www..com");
$host = "111.13.100.92"; //設置基本信息
$port = 65530;
set_time_limit(0); //設置超時時間
//創建一個socket
$socket = socket_create(AF_INET,SOCK_STREAM,0) or die("不能建立socket鏈接!n");
//綁定Socket到埠
$result = socket_bind($socket,$host,$port) or die("不能綁定socket給定的埠n");
//開始監聽
$result = socket_listen($socket,3) or die("建立socket連接失敗n");
//接受連接請求,另一個Socket處理通訊
$socket_a = socket_accept($socket) or die("不能接受客戶端socket請求n");
//獲取客戶端的輸入請求
$input = socket_read($socket_a,4096) or die("讀取客戶端輸入失敗n");
//清空輸入字元
$input = trim($input);
//處理客戶端輸入並處理結果
$output = strrev($input)."n";
socket_write($socket_a,$output,strlen($output)) or die("不能給客戶端返回結果n");
//關閉socket
socket_close($socket_a);
socket_close($socket);
?>
PHP網路編程的代碼怎麼寫?這段php網路編程,希望大家一定要學會。
本篇《PHP網路編程的代碼怎麼寫?原來這個代碼就足夠我們使用了》到這里就已經結束了,小編一直認為,某一個編程軟體受歡迎是有一定原因的,首先吸引人的一定是其功能,環球網校的小編祝您PHP學習之路順利,如果你還想知道更多php知識,可以點擊本站的其他文章進行學習。
Ⅷ PHP中寫一個資料庫查詢的類的方法代碼要如何寫
<?php
if(!defined("INCLUDE_MYSQL_OK")) {
define("INCLUDE_MYSQL_OK","");
class MySQL_class {
var $debug = true;
var $db,
$id,
$result, /* 查詢結果指針 */
$rows, /* 查詢結果行數 */
$fields, /* 查詢結果列數 */
$data, /* 數據結果 */
$arows, /* 發生作用的紀錄行數目 */
$iid; /* 上次插入操作後,可能存在的"AUTO_INCREMENT"屬性欄位的值,如果為"0",則為空 */
var $user, $pass, $host, $charset;
/*
* 請注意用戶名和密碼是否正確
*/
function Setup ($host, $user, $pass, $charset='utf8') {
$this->host = $host;
$this->user = $user;
$this->pass = $pass;
$this->charset = $charset;
}
function Connect ($db = "") {
global $CFG_MYSQL_INFO;
if (!$this->host) {
$this->host = $CFG_MYSQL_INFO["host"];
}
if (!$this->user) {
$this->user = $CFG_MYSQL_INFO["user"]; /* 在這里作修改 */
}
if (!$this->pass) {
$this->pass = $CFG_MYSQL_INFO["passwd"]; /* 在這里作修改 */
}
if (!$this->charset) {
$this->charset = "utf8"; /* 在這里作修改 */
}
if (empty($db))
$this->db = $CFG_MYSQL_INFO["database"];
else
$this->db = $db;
$this->id = @mysql_connect($this->host, $this->user, $this->pass);
if (!$this->id)
return false;
$this->SelectDB($this->db); /* 定位到指定資料庫 */
$this->Query("SET NAMES '".$this->charset."'");
return true;
}
function Close(){
@mysql_close($this->id);
}
function SelectDB ($db) {
if(!@mysql_select_db($db, $this->id))
return false;
else
return true;
}
function Begin () {
$this->result = @mysql_query("START TRANSACTION WITH CONSISTENT SNAPSHOT", $this->id);
if (!$this->result)
return false;
return true;
}
function Commit () {
$this->result = @mysql_query("COMMIT", $this->id);
if (!$this->result)
return false;
return true;
}
function Rollback () {
$this->result = @mysql_query("ROLLBACK", $this->id);
if (!$this->result)
return false;
return true;
}
function Escape ($str) {
$escstr = mysql_escape_string($str);
return $escstr;
}
# 普通查詢功能,主要用於返回結果是多條記錄的情況
# 請使用 Fetch 方法取得每條記錄信息
function Query ($query) {
$this->result = @mysql_query($query, $this->id);
if (!$this->result)
{
if ($this->debug)
MySQL_ErrorMsg ("不能執行查詢(query): $query");
else
return false;
}
$this->rows = @mysql_num_rows($this->result);
$this->fields = @mysql_num_fields($this->result);
if (!$this->rows) return false;
return true;
}
function QuerySql ($query) {
$ret = @mysql_query($query, $this->id);
if ($ret === false)
{
if ($this->debug)
MySQL_ErrorMsg ("不能執行查詢(query): $query");
else
return false;
}
$this->result = $ret;
$this->rows = @mysql_num_rows($this->result);
$this->fields = @mysql_num_fields($this->result);
return true;
}
# 如果查詢結果為單條記錄時使用,返回結果存儲於數組 data 中
function QueryRow ($query) {
$this->result = @mysql_query($query, $this->id);
if (!$this->result)
{
if ($this->debug)
MySQL_ErrorMsg ("不能執行查詢(query): $query");
else
return false;
}
$this->rows = @mysql_num_rows($this->result);
$this->data = @mysql_fetch_array($this->result, MYSQL_ASSOC);
//MySQL_ErrorMsg ("不能從查詢結果中取得數據 $query");
if (!$this->result || !$this->rows)
return false;
return true;
}
# 移動到指定記錄行,將該行結果儲存於數組 data 中
function Fetch ($row) {
if(!@mysql_data_seek($this->result, $row))
//MySQL_ErrorMsg ("不能定位到指定數據行 $row");
return false;
$this->data = @mysql_fetch_array($this->result, MYSQL_ASSOC);
//MySQL_ErrorMsg ("不能提取指定數據行數據 $row");
if (!$this->data)
return false;
return true;
}
/* 以下方法將作用於 arows */
/* 此方法將作用於 iid */
function Insert ($query) {
$this->result = @mysql_query($query, $this->id);
if (!$this->result)
{
if ($this->debug)
MySQL_ErrorMsg ("不能執行查詢(query): $query");
else
return false;
}
$this->arows = @mysql_affected_rows($this->id);
$this->iid = @mysql_insert_id($this->id);
return true;
}
function Update ($query) {
$this->result = @mysql_query($query, $this->id);
if (!$this->result)
{
if ($this->debug)
MySQL_ErrorMsg ("不能執行查詢(query): $query");
else
return false;
}
$this->arows = @mysql_affected_rows($this->id);
if (!$this->arows || $this->arows == -1)
return false;
return true;
}
function Delete ($query) {
$this->result = @mysql_query($query, $this->id);
if (!$this->result)
{
if ($this->debug)
MySQL_ErrorMsg ("不能執行查詢(query): $query");
else
return false;
}
$this->arows = @mysql_affected_rows($this->id);
return true;
}
function Error (){
return mysql_error()."(".mysql_errno().")";
}
function Errno (){
return mysql_errno();
}
}
/*
* MySQL_ErrorMsg
* 輸出錯誤信息
*/
function MySQL_ErrorMsg ($msg) {
# 關閉可能影響字元顯示的HTML代碼
echo("</ul></dl></ol>\n");
echo("</table></script>\n");
# 錯誤信息
$text = "<font color=\"#000000\" style=\"font-size: 9pt; line-height: 12pt\"><p>系統提示:".$msg."<br>";
$text .= "錯誤信息:";
$text .= mysql_error()."<br>";
$text .= "錯誤代碼:".mysql_errno()."<br><br>";
$text .= "請稍候再試,如果問題仍然存在,請與 <a href=\"mailto:[email protected]\">系統管理員</a> 聯系!";
$text .= "</font>\n";
die($text);
}
}
?>
一些細節的地方自己修改吧 主要是我在別的文件專門定義了全局變數,你看一遍,把應改的地方改一下就好了
Ⅸ 怎麼編寫PHP程序
有關PHP的安裝配置,可以查閱網頁陶吧上的「PHP安裝全攻略」專題文章。
3.3 語法從語法上看,PHP語言近似於C語言。可以說,PHP是借鑒C語言的語法特徵,由C語言改進而來的。我們可以混合編寫PHP代碼和HTML代碼,不僅可以將PHP腳本嵌入到 HTML 文件中,我們甚至還可以把 HTML 標簽也嵌入在 PHP 腳本里。以下是你可以採用的幾種方法。你可以選用其中一種你最適合的並且就這樣堅持這種方法!
從HTML中分離
以下是可以使用的方法:
<script language="php" . . . </script
<% . . . %
註:當你使用「<? . . . ?」將PHP代碼嵌入於HTML文件中時,可能會同XML發生沖突,同時,能否使用這一縮減形式還取決於PHP本身的設置。為了可適應XML和其它編輯器,你可以在開始的問號後面加上「php」使PHP代碼適應於XML分析器。如:?lt;?php. . . ?」。也可以像寫其它腳本語言那樣使用腳本標記,如:「<script language="php" . . . </script」。
語句與Perl和C一樣,在PHP中用「;」來分隔語句。那些從HTML中分離出來的標志也表示語句的結束。
注釋PHP支持C,C++和Unix風格的注釋方式:
/* C,C++風格多行注釋 */
// C++風格單行注釋
# Unix風格單行注釋
echo 和 print
PHP 和 HTML 最簡單的交互是通過 print 和 echo 語句來實現的,在實際使用中, print 和 echo 兩者的功能幾乎是完全一樣。可以這么說,凡是有一個可以使用的地方,另一個也可以使用。但是,兩者之間也還是一個非常重要的區別:在 echo 函數中,可以同時輸出多個字元串,而在 print 函數中則只可以同時輸出一個字元串。同時,echo函數並不需要圓括弧,所以echo函數更像是語句而不像是函數。讓我們來看看下面這一實例:<?$a="hello";
$b="world";
echo "a","b";
print "a","b";?用瀏覽器觀看這段代碼的運行情況後,你會看到這樣的運行結果:abaParse error: parse error in d:adminmyphphometest.php3 on line 5
這說明這段代碼並不能完全通過解釋,發生錯誤的地方就在代碼的第五行:「print "a","b";」。
3.4一個簡單的實例
通過我們已經學過的知識,你可以編寫一個最簡單的程序輸出一個也許是程序世界中最有名的詞語<HTML<HEAD<TITLE<?echo "Hello World!";?</TITLE</HEAD<BODY<H1First PHP page</H1<HR<?// Single line C++ style comment/*printing the message*/echo "Hello World!";
# Unix style single line comment?</BODY</HTML找本書坐下來看下,學一門語言至少要靜下心來研究一周,再加上不斷的實踐!補充:
Ⅹ 基於php開發的網站系統技術實現方法怎麼寫
套套模板永遠是不會技術進步的,還是要自己多寫代碼才行,TP這東西他只是一個核心,具體功能需要自己去實現,用這個自己開發東西,還是能提高一定能力的,但他把底層一些東西都弄好了,所以你要學習底層的那些資料庫連接等就需要自己去完全手寫了。歸總來講,還是要多動手寫實際功能性的代碼。從資料庫如何設計到網站程序的結構如何架構這些都是重要的。如果你永遠停留 在套套模板,那你永遠也就只能停留 在那個水平了。