导航:首页 > 编程语言 > 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基本代码相关的资料

热点内容
超级命令的英文 浏览:781
做账为什么要用加密狗 浏览:583
考研群体怎么解压 浏览:156
linux修改命令提示符 浏览:224
圆圈里面k图标是什么app 浏览:59
pdf加空白页 浏览:945
linux服务器如何看网卡状态 浏览:316
解压新奇特视频 浏览:705
图书信息管理系统java 浏览:553
各种直线命令详解 浏览:863
程序员泪奔 浏览:147
素材怎么上传到服务器 浏览:516
android百度离线地图开发 浏览:191
web可视化编程软件 浏览:294
java笔试编程题 浏览:746
win11什么时候可以装安卓 浏览:564
java不写this 浏览:1001
云点播电影网php源码 浏览:97
pythonclass使用方法 浏览:226
移动加密软件去哪下载 浏览:294