導航:首頁 > 編程語言 > php基本代碼

php基本代碼

發布時間:2022-08-12 14:19:48

❶ 一段php代碼該怎麼寫

根據你的描述,好像是顯示產品的一個格式,$a, $id,$num,$money分別是對應各個產品的屬性,$count則是計算所有產品的總價值,那麼php代碼可以這樣寫:
<?php
$a = explode('|', '610|629');
$id = explode('|', '3171|2486');
$num = explode('|', '8|5');
$money = explode('|', '1|1');
$count = 0;

$totalNum = count($a);
echo count($a) . "<br>";
$str = "{";
for ($i = 0; $i < $totalNum; $i++) {
/*
$str .= '\"';
$str .= $a[$i];
$str .= '\":{\"id\":';
$str .= $id[$i];
$str .= ',';
$str .= '\"num\":';
$str .= $num[$i];
$str .= ',\"money\":';
$str .= $money[$i];
$str .= '},';
*/
$str .= sprintf('\"%d\":{\"id\":%d,\"num\":%d,\"money\":%d},', $a[$i], $id[$i], $num[$i], $money[$i]);
$count += ($num[$i] * $money[$i]);
}
$str .= '\"Count\":';
$str .= $count;
$str .= '}';
echo $str;

❷ PHP的查詢代碼

1.php代碼 a.php?t=1

//a.phpt是列表type
$type=$_GET['t'];
if($type==='1')
{
$where_sql="wherelxtclike'樂享%'";
}elseif($type==='2')
{
$where_sql="wherelxtclike'新融合%'";
}elseif($type==='3'){
$where_sql="wherelxtclike'新融合%'ORlxtclike'樂享%'";
}else{
$where_sql='where1';//所有的
}
$sql="select*from`table`".$where_sql;
$num_sql="selectcount(*)asnumfrom`table`".$where_sql;
//獲取統計總數
//$db是mysql對象其實就是查詢兩條sql語句的對象簡寫如下
$db->query($num_sql);
//列表
$row=$db->query($sql);
//循環$row就是結果

單單數據邏輯不麻煩,難點應該是sql語句的書寫。用到like % 第二用到OR連接,

❸ 求個簡單的php代碼

_tags($string, $replace_with_space = true)
{
if ($replace_with_space) {
return preg_replace('!<[^>]*?>!', ' ', $string);
} else {
return strip_tags($string);
}
}

截取字元函數(匹配各種編碼)
function truncate($string, $length = 80, $etc = '...', $break_words = false, $middle = false){
if ($length == 0)
return '';

if (is_callable('mb_strlen')) {
if (mb_detect_encoding($string, 'UTF-8, ISO-8859-1') === 'UTF-8') {
// $string has utf-8 encoding
if (mb_strlen($string) > $length) {
$length -= min($length, mb_strlen($etc));
if (!$break_words && !$middle) {
$string = preg_replace('/\s+?(\S+)?$/u', '', mb_substr($string, 0, $length + 1));
}
if (!$middle) {
return mb_substr($string, 0, $length) . $etc;
} else {
return mb_substr($string, 0, $length / 2) . $etc . mb_substr($string, - $length / 2);
}
} else {
return $string;
}
}
}
// $string has no utf-8 encoding
if (strlen($string) > $length) {
$length -= min($length, strlen($etc));
if (!$break_words && !$middle) {
$string = preg_replace('/\s+?(\S+)?$/', '', substr($string, 0, $length + 1));
}
if (!$middle) {
return substr($string, 0, $length) . $etc;
} else {
return substr($string, 0, $length / 2) . $etc . substr($string, - $length / 2);
}
} else {
return $string;
}
}

綜合就是
$arc=strip_tags($arc);
$arc=truncate($arc,200)

❹ php語句代碼

好像哦,只是好像,在php里,單純的變數在雙引號里可以正確傳值,但數組不行,必須用「.」運算符連接。
<?php
$a="<a href=\"delphp-id.php?id=".$row[0]."\">";
?>
不在<?php ?>之間的話:
<a href="delphp-id.php?id=<?php $row[0];?>"><?php $row[0];?></a>

補一句,<? ?>有些伺服器上可能不認哦,最好寫成<?php ?>,以免將來的麻煩。

❺ 幫忙些段簡單的PHP代碼

<?php
$type
=
$_GET["type"];
////下面這個是進入選擇的值,根據這個值進入頁面
$html
=
"<script>";
$html
.=
"window.location.href='".
$type.".php'";
$html
.=
"</script>";
echo
$html;
//如果你想做別的
switch($type){
case
'qq':
echo
"你進入了QQ,接下來你想做什麼可以在這里再做判斷";
break;
case
'msn'"
echo
"你進入了MSN,接下來你想做什麼可以在這里再做判斷";
break;
}
如果還有別的要求,可以接著說,或著給我發求助之類的,我能幫的會幫的!
?>

❻ 求PHP常用代碼大全

if ($da="") { echo "<SCRIPT language=javaScript>alert('問題答案不能為空');"; echo"this.location.href='vbscript:history.back()';</SCRIPT>"; } if ($qq!="") { if (!is_numeric($qq)) { echo "<SCRIPT language=JavaScript>alert('QQ號碼必須是數字');"; echo"this.location.href='vbscript:history.back()';</SCRIPT>"; } } if ($youbian=="" or strlen($youbian)!=6) { echo "<SCRIPT language=JavaScript>alert('請正確輸入郵編');"; echo"this.location.href='vbscript:history.back()';</SCRIPT>"; } if ($youbian!="") { if (!is_numeric($youbian)) { echo "<SCRIPT language=JavaScript>alert('郵編必須是數字');"; echo"this.location.href='vbscript:history.back()';</SCRIPT>"; } } if ($di="") { echo "<SCRIPT language=JavaScript>alert('住址不能為空');"; echo"this.location.href='vbscript:history.back()';</SCRIPT>"; } if ($mail=="") { echo "<SCRIPT language=JavaScript>alert('E-mail不能為空!');"; echo "this.location.href='vbscript:history.back()';</SCRIPT>"; } if ($textarea=="") { echo "<SCRIPT language=JavaScript>alert('個人說明不能為空!');"; echo "this.location.href='vbscript:history.back()';</SCRIPT>"; } if ($textarea=="" or strlen(textarea)>150) { echo "<SCRIPT language=JavaScript>alert('個人說明為150個字元');"; echo"this.location.href='vbscript:history.back()';</SCRIPT>"; } 24、對輸出的內容進行判斷,從而輸出其它結果 <?php if ($rs["active"]==1) { echo "<font color='#ff0000'>激活</font>"; }else{ echo "禁用"; } ?> 25.字元截取函數 <?=substr("$rs[zixun_biaoti]",0,28 )?> 26.男女問題或單選帶選擇的 <input type="radio" name="hy_zhuangtai" value="男" <?php if ($rs["hy_zhungtai"]==="男") { echo "checked";}?>> 男 <input type="radio" name="hy_zhuangtai" value="女" <?php if ($rs["hy_zhuangtai"]==="女") { echo "checked";}?>> 女 27.單選不帶單選框的 <?php if ($rs['hy_zhuangtai']=='鎖定'){?> <a href="Userzt.php?action=yes&id=<?php echo $rs['hy_id'];?>">鎖定</a> <?php } else{ ?><a href="Userzt.php?id=<?php echo $rs['hy_id'];?>&action=no">解鎖</a> <?php }?> 它的save頁是 <?php require_once('../../conn.php'); ?> <?php $hy_id=$_GET['id']; $action=$_GET['action']; if ($action=='yes'){ $sql="update hybiao set hy_zhuangtai='鎖定' where hy_id='$id'"; $query=mysql_query($sql,$connec); echo("<script type='text/javascript'>location.href='UserManage.php';</script>"); } else{ $sql="update hybiao set hy_zhuangtai='正常' where hy_id='$id'"; $query=mysql_query($sql,$connec); echo("<script type='text/javascript'>location.href='UserManage.php';</script>"); } mysql_close(); ?> 28.如果文字過長,則將過長的部分變成省略號顯示 <DIV STYLE="width: 120px; height: 50px; border: 0px solid blue;overflow: hidden; text-overflow:ellipsis"> <NOBR>就是比如有一行文字,很長,表格內一行顯示不下.</NOBR> </DIV> 29. 禁止復制,滑鼠拖動選取 <body ondragstart=window.event.returnValue=false oncontextmenu=window.event.returnValue=false onselectstart=event.returnValue=false> 30.大中小 文字的變化 <script type="text/javascript"> function doZoom(size) {document.getElementById('zoom').style.fontSize=size+'px';} </script> <span id="zoom">需要指定大小的文字</span> <a href="javascript:doZoom(16)">大</a> <a href="javascript:doZoom(14)">中</a> <a href="javascript:doZoom(12)">小</a> 30. 添加到收藏夾和設為首頁 <a href=# onclick="this.style.behavior='url(#default#homepage)';this.setHomePage(' http://www.makewing.com/lanren/' );">設為首頁</a> <a href="javascript:window.external.AddFavorite(' http://www.makewing.com/lanren/',' 懶人圖庫')">收藏本站</a> 31. 記錄並顯示網頁的最後修改時間 <script language=JavaScript> document.write("最後更新時間: " + document.lastModified + "") </script> 32. 節日倒計時 <Script Language="JavaScript"> var timedate= new Date("October 1,2002"); var times= "國慶節"; var now = new Date(); var date = timedate.getTime() - now.getTime(); var time = Math.floor(date / (1000 * 60 * 60 * 24)); if (time >= 0) document.write( "現在離"+times+"還有: "+time +"天") </Script> 33. 打開窗口即最大化 <script language="JavaScript"> <!-- Begin self.moveTo(0,0) self.resizeTo(screen.availWidth,screen.availHeight) // End --> </script> 34. 加入背景音樂 <bgsound src="mid/windblue[1].mid" loop="-1"> 只適用於IE <embed src="music.mid" autostart="true" loop="true" hidden="true"> 對Netscape ,IE 都適用 35. 滾動 <marquee direction=up height=146 onmouseout=start() onmouseover=stop() scrollAmount=2> 滾動信息 </marquee> 36. 防止點擊空鏈接時,頁面往往重置到頁首端 代碼「javascript:void(null)」代替原來的「#」標記 37. 不能點右鍵,不用CTRL+A,不能復製作! <body oncontextmenu="window.event.returnValue=false" onkeypress="window.event.returnValue=false" onkeydown="window.event.returnValue=false" onkeyup="window.event.returnValue=false" ondragstart="window.event.returnValue=false" onselectstart="event.returnValue=false"> </body> 37. 隨機變換背景圖象(一個可以刷新心情的特效) <Script Language="JavaScript"> image = new Array(4); //定義image為圖片數量的數組 image [0] = 'tu0.gif' //背景圖象的路徑 image [1] = 'tu1.gif' image [2] = 'tu2.gif' image [3] = 'tu3.gif' image [4] = 'tu4.gif' number = Math.floor(Math.random() * image.length); document.write("<BODY BACKGROUND="+image[number]+">"); </Script> 38. 劃過鏈接 手型滑鼠 style="cursor:hand" 39. 如何關閉層 <div id="Layer1"></div> <a href="#" onClick="Layer1.style.display='none'">關閉層</a> 40. <a href=javascript:close()>[關閉窗口]</a> 41. 凹陷文字背景為灰色 <div style="width:300px;padding:20px;overflow:hidden;word-wrap:break-word;word-break:break:all; font-size:12px; line-height:18px; background-color:#eeeeee;"> <font disabled> 怎麼樣,我凹下去了吧?<br> 你不想試試嗎?<br> <a href=" www.lenvo.cn http://www.lenvo.cn/">www.lenvo.cn </div> 42. 給表格做鏈接 <table width="100%" onclick="window.open(' http://www.makewing.com/', '_blank')" style="CURSOR:hand"> <tr> <td height="100" bgcolor="f4f4f4"> </td> </tr> </table> 43. 後退&關閉窗口 後退:javascript:history.back(1) 關閉:javascript:window.close(); 44. 如果文字過長,則將過長的部分變成省略號顯示 <DIV STYLE="width: 120px; height: 50px; border: 0px solid blue;overflow: hidden; text-overflow:ellipsis"> <NOBR>就是比如有一行文字,很長,表格內一行顯示不下.</NOBR> </DIV> 45. 禁止復制,滑鼠拖動選取 <body ondragstart=window.event.returnValue=false oncontextmenu=window.event.returnValue=false onselectstart=event.returnValue=false>

❼ PHP代碼解釋

<?php
header("content-type:text/html;charset=utf-8");//設置編碼集
include_once("system/system.inc.php");//引用配置文件
$sql="select * from tb_links";//sql語句
$linkarr=$admindb->ExecSQL($sql,$conn);//執行SQL
$smarty->assign('linkarr',$linkarr);//實例化對象
$smarty->assign('title','查看連接');
$smarty->display('showlinks.tpl');//在showlinks.tpl模版文件裡面可以用{$linkarr}接收資料庫值
?>

❽ 最簡單 php 代碼

<?php

mysql_query("insert into guahao values('".$name."','".$nl."','".$shouji."','".$sname."','".$info."')");
?>

❾ 簡單PHP代碼

$_env 是環境變數,通過環境方式傳遞給當前腳本的變數的數組。

$_ENV['defaultapp'] = array('portal.php' => 'portal', 'forum.php' => 'forum', 'group.php' => 'group', 'home.php' => 'home');
是賦值 , 你可以用 var_mp($_env['defaultapp']) 看賦值結果。
--------------------------------------------------------------------
$_ENV['hostarr'] = explode('.', $_SERVER['HTTP_HOST']);
環境變數 用.分隔 主域名(你可以 echo $_server['HTTP_HOST']裡面有什麼)
----------------------------------------------------------------
$url = $domainroot.'forum.php?mod=group&fid='.$domain['id'].'&page=1';
構造一個URL 直白點 結果就是: www.some.com/forum.php?mod=1&fid=1&page=1
----------------------------------------
$url = empty($_ENV['domain']['app']['default']) ? (!empty($_ENV['domain']['defaultindex']) ? $_ENV['domain']['defaultindex'] : 'forum.php') : 'http://'.$_ENV['domain']['app']['default'];
結構簡化 $url = $a ? (!$b? $c : $d) :$e; 2個3元運算嵌套, 至於看起來復雜的變數都是多維數組的值

閱讀全文

與php基本代碼相關的資料

熱點內容
php個性qq源碼 瀏覽:821
初學c語言顯示源未編譯 瀏覽:245
資產概況源碼 瀏覽:472
dos命令建文件夾命令 瀏覽:379
解壓的密碼htm被屏蔽 瀏覽:502
冬天太冷冰箱壓縮機不啟動怎麼辦 瀏覽:83
手機打開vcf需要什麼編譯器 瀏覽:910
加密磁碟後開機很慢 瀏覽:271
長沙智能雲控系統源碼 瀏覽:258
阿里雲伺服器如何設置操作系統 瀏覽:999
超級命令的英文 瀏覽:784
做賬為什麼要用加密狗 瀏覽:586
考研群體怎麼解壓 瀏覽:159
linux修改命令提示符 瀏覽:226
圓圈裡面k圖標是什麼app 瀏覽:63
pdf加空白頁 瀏覽:948
linux伺服器如何看網卡狀態 瀏覽:318
解壓新奇特視頻 瀏覽:707
圖書信息管理系統java 瀏覽:554
各種直線命令詳解 瀏覽:864