当前位置: 首页 > 图文教程 > 网络编程 > PHP > 初学PHP的18个基础例程

PHP
php 正确解码javascript中通过escape编码后的字符
在PHP中养成7个面向对象的好习惯
PHP函数常用用法小结
Zend framework处理一个http请求的流程分析
用js进行url编码后用php反解以及用php实现js的escape功能函数总结
php cli 方式 在crotab中运行解决
PHPWind 发帖回帖Api PHP版打包下载
Linux下将excel数据导入到mssql数据库中的方法
php不用内置函数对数组排序的两个算法代码
用php实现的下载css文件中的图片的代码
php 获取当前访问的url文件名的方法小结
php date与gmdate的获取日期的区别
php下把数组保存为文件格式的实例应用
劣质的PHP代码简化
php 生成随机验证码图片代码
php+mysql事务rollback&commit示例
php 处理上百万条的数据库如何提高处理查询速度
两个开源的Php输出Excel文件类
PHP Memcached应用实现代码
Memcache 在PHP中的使用技巧

初学PHP的18个基础例程


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 27 ::
收藏到网摘: n/a

如何创建我们的第一个PHP页面呢?非常简单的!选择我们使用的一个最好的设计工具,当然你也可以 只使用记事本。创建之后记得要保存为扩展名为PHP的文件,然后传到我们的服务器上。

  在编写PHP程序之前通常我们需要配置我们的环境,也就是说服务器要支持PHP才能行啊

  一、PHP的基本结构:

  使用Include函数

<Html>
<Head>
<title>Your page Subject and domain name</title>

  上面内容为我们使用的每个页面的标题,不要动。

  每个页的头部:

<Meta NAME="" CONTENT="">
"" your others meta tag
"" your others meta tag
"" your others meta tag
"" your others meta tag
"" your others meta tag
"" your others meta tag
"" your others meta tag
重要的javascripts代码放这
CSS设置放这

  上述内容保存为header.php,使每个页面的头部都是一样的。

<?PHP include("header.php")?>

</head>
<body>

  你的页的所有内容

</body>
</html>

  保存为footer.php,使每个页面的底部都一样。

<? include("footer.php");?>

  填写我们的版权信息

</body>
</html>

  二:如何输出文本或者把文本建立连接用PHP

  在PHP中如何显示文本呢?使用下面的命令:

<?php echo "Hello in php";?>

  如何创建一个连接呢?

<?php echo "<a href=\"http://www.webjx.com\">
www.webjx.com.com[/url]";?>

  如何创建一个有style的连接呢?

<?php echo "<font style=\"color:blue;font-size:10px;font- family:verdana;\">Free Scripts By: <a href=\"http://www.webjx.com.com\" target=\"_blank\" title=\"Free Scripts By: webjx.com\">
http://www.webjx.com</font>[/url]";?>

  "echo"是用来显示输出的。

  三:如何实现分页:

  如果好多内容在你的页面中这时我们就考虑用分页形式来实现显示了。

  简单的分页代码:

<html>
<head>
<title>webjx.com</title>
</head>
<body text="#000000">
<center>
<table width="500" border="3">
<tr>
<td width="140" height="400" valign="top">
<p align="center">
<a href='index.php'>home[/url]

<a href='index.php?p=Page1'>page 1[/url]

<a href='index.php?p=Page2'>page 2[/url]

</p></td>
<td width="360" height="400" valign="top">
<p>
<?
function index()
{
echo "<p align=center>Welcome to this tutorial
Here you can find funny
tricks</p>





"; }
$choice=$_GET['p'];

switch($choice)
{
case "Page1":

echo "<p align=center>Page1 text, img and so on here</p>";
break;

case "Page2":

echo "<p align=center>Page2 text, img and so on here</p>";
break;

default:
index();
}

?>

</p>
</td>
</tr>
</table> </center>
</body>
</html>

  以上文件必须保存为index.php

  高级分页的代码:

<html>
<head>
<title>webjx.com</title>
</head>
<body text="#000000">
<center>
<table width="50