php注意事项

时间:2014-05-28 19:10:54   收藏:0   阅读:429

获取表单信息

<?php
if($_POST["submit"]=="登录"){
 echo "您输入的用户名为:".$_POST[user]."&nbsp;&nbsp;密码为:".$_POST[pwd];
}
?>

 

 

 

number_format()函数对指定的数字字符串进行格式化

<?php
$number = 2668.746;         //定义数字字符串常量
echo number_format($number);      //输出1个参数格式化后的数字字符串
echo "<br>";          //执行换行
echo number_format($number, 2);      //输出2个参数格式化后的数字字符串
echo "<br>";          //执行换行
$number2 = 123456.7832;        //定义数字字符串常量
echo number_format($number2, 2, ‘.‘, ‘.‘);   //输出4个参数格式化后的数字字符串
?>

显示2,669
2,668.75
123.456.78

 

 

 

<?php
echo strstr("明日编程词典网","编");     //输出查询的字符串
echo "<br>";          //执行换行
echo strstr("http://www.mrbccd.com","w");   //输出查询的字符串
echo "<br>";          //执行换行
echo strstr("0431-84978981","8");     //输出查询的字符串
?>显示为

编程词典网
www.mrbccd.com
84978981

 

strlen字符长度

获取字符长度

<?php
echo substr("www.mrbccd.com",0);        //从第0个字符开始截取
echo "<br>";
echo substr("www.mrbccd.com",4,10);      //从第4个字符开始连续截取10个字符
echo "<br>";
echo substr("www.mrbccd.com",-4,4);        //从倒数第4个开始截取4个字符
echo "<br>";
echo substr("www.mrbccd.com",0,-4);        //从第一个字符开始截取,截取到倒数第4个字符
?>

<?php
$str1="str2.jpg";        //定义字符串常量
$str2="str10.jpg";        //定义字符串常量
$str3="mrsoft1";        //定义字符串常量
$str4="MRSOFT2";        //定义字符串常量
echo strcmp($str1,$str2);          //按字节进行比较,返回1
echo strcmp($str3,$str4);          //按字节进行比较,返回1
echo strnatcmp($str1,$str2);       //按自然排序法进行比较,返回-1
echo strnatcmp($str3,$str4);       //按自然排序法进行比较,返回1
?>

显示11-11

 

<?php
 $str = "select * from tb_book where bookname = ‘PHP项目开发全程实录‘";
 $a = addslashes($str);       //对字符串中的特殊字符进行转义
 echo $a."<br>";        //输出转义后的字符
 $b = stripslashes($a);       //对转义后的字符进行还原
 echo $b."<br>";        //将字符原义输出
?>

<?php
$a="编程体验网";                  //对指定范围内的字符进行转义
$b=addcslashes($a,"编程体验网");       //转义指定的字符串
echo "转义字符串:".$b;       //输出转义后的字符串
echo "<br>";          //执行换行
$c=stripcslashes($b);                //对转义的字符串进行还原
echo "还原字符串:".$c;       //输出还原后的转义字符串
?>

显示结果

转义字符串:\261\340\263\314\314\345\321\351\315\370
还原字符串:编程体验网

 

 

时间打印<?php

echo "<font color=‘#ffff00‘>北京时间:". date("Y-m-d H:i:s ")."</font>"

?>

 

 

 

显示表单内容

<table width="703" border="0" align="center" cellpadding="0" cellspacing="0">

  <tr>

    <td  bgcolor="#669933" ><table width="703" border="0" align="center" cellpadding="0" cellspacing="1">

      <tr>

        <td height="25" colspan="5" align="center" bgcolor="#FFFFFF"><span class="STYLE1">企业公告信息展示</span></td>

      </tr>

      <tr>

        <td width="187" height="25" align="center" bgcolor="#CCFF66">标题</td>

        <td width="173" align="center" bgcolor="#CCFF66">内容</td>

        <td width="101" align="center" bgcolor="#CCFF66">发布时间</td>

      </tr>

  <?php

  $conn=mysql_connect("localhost","root","root");

  mysql_select_db("db_database04",$conn);

  mysql_query("set names gb2312");

  $sql=mysql_query("select * from tb_person order by u_id desc",$conn);

  $info=mysql_fetch_array($sql);

   if($info==false){

  echo "暂无图书信息!";

}

else{   

  do{

  ?>

      <tr>

        <td height="25" align="center" bgcolor="#FFFFFF"><?php echo $info[p_title];?></td>

        <td height="25" align="center" bgcolor="#FFFFFF"><?php echo $info[p_content];?></td>

        <td height="25" align="center" bgcolor="#FFFFFF"><?php echo $info[p_time];?></td>

      </tr>

  <?php

      }while($info=mysql_fetch_array($sql));  

}

  ?>

    </table></td>

  </tr>

</table>

 

时间打印<?php

echo "<font color=‘#ffff00‘>北京时间:". date("Y-m-d H:i:s ")."</font>"

?>

 

显示表单内容

<table width="703" border="0" align="center" cellpadding="0" cellspacing="0">

  <tr>

    <td  bgcolor="#669933" ><table width="703" border="0" align="center" cellpadding="0" cellspacing="1">

      <tr>

        <td height="25" colspan="5" align="center" bgcolor="#FFFFFF"><span class="STYLE1">企业公告信息展示</span></td>

      </tr>

      <tr>

        <td width="187" height="25" align="center" bgcolor="#CCFF66">标题</td>

        <td width="173" align="center" bgcolor="#CCFF66">内容</td>

        <td width="101" align="center" bgcolor="#CCFF66">发布时间</td>

      </tr>

  <?php

  $conn=mysql_connect("localhost","root","root");

  mysql_select_db("db_database04",$conn);

  mysql_query("set names gb2312");

  $sql=mysql_query("select * from tb_person order by u_id desc",$conn);

  $info=mysql_fetch_array($sql);

   if($info==false){

  echo "暂无图书信息!";

}

else{   

  do{

  ?>

      <tr>

        <td height="25" align="center" bgcolor="#FFFFFF"><?php echo $info[p_title];?></td>

        <td height="25" align="center" bgcolor="#FFFFFF"><?php echo $info[p_content];?></td>

        <td height="25" align="center" bgcolor="#FFFFFF"><?php echo $info[p_time];?></td>

      </tr>

  <?php

      }while($info=mysql_fetch_array($sql));  

}

  ?>

  </table></td>

  </tr>

</table>

 

使用include_once可以避免此错误,一般都_once用的比较多。应该根据实际情况需求include和_once的区别 

include和require区别
当要包含的文件不存在时,include产生一个警告(Warning),该语句后面的程序会继续执行;而 require则导致一个致命错误(Fatal error),程序就此终止

require_once()include_once()语句分别对应于require()include()语句。require_once()include_once()语句主要用于需要包含多个文件时,可以有效地避免把同一段代码包含进去而出现函数或变量重复定义的错误。

 

 

 

 

 

1、这个方法是个替换字符串内字符的功能。
2、这是个方法 如果你程序内没有调用这个方法 那么你删掉他当然没有影响。
3、如果你调用了这个方法 并且你把这个方法删了 他会报错的 说找不到这个方法。如果没报错 可能是你把错误提示关闭了。
还有 如果在插入数据库之前你调用他 插入数据库的 $content 变量就是替换完的变量 如果没调用 或调用失败 那么插入数据库的就是 $content原来的内容。
你不注意的话是看不出来的。因为这个方法替换的只是几个不起眼的字符串或标签等。
function.php
<?php

function unhtml($content)

 {
  
 $content=htmlspecialchars($content);
 
 $content=str_replace(chr(13),"<br>",$content);

 $content=str_replace(chr(32),"&nbsp;",$content);

 $content=str_replace("[_[","<",$content);
 
 $content=str_replace("]_]",">",$content);
  
 $content=str_replace("|_|"," ",$content);
  
return trim($content);
}
?>

php注意事项,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!