加入收藏 | 设为首页 | 会员中心 | 我要投稿 源码门户网 (https://www.92codes.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

新手入门 初学动态网页PHP的10个例子

发布时间:2022-03-08 20:12:13 所属栏目:PHP教程 来源:互联网
导读:如何创建我们的第一个PHP页面呢?非常简单的!选择我们使用的一个最好的设计工具,当然你也可以 只使用记事本。创建之后记得要保存为扩展名为PHP的文件,然后传到我们的服务器上。 在编写PHP程序之前通常我们需要配置我们的环境,也就是说服务器要支持PHP
  如何创建我们的第一个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.CuoXIn.com/">www.CuoXIn.com.com</a>";?>
 
  如何创建一个有style的连接呢?
 
  <?php echo "<font style=/"color:blue;font-size:10px;font- family:verdana;/">Free Scripts By: <a href=/"http://www.CuoXIn.com.com/" target=/"_blank/" title=/"Free Scripts By: CuoXIn.com/">http://www.CuoXIn.com</font></a>";?>
 
  "echo"是用来显示输出的。
 
  三、如何实现分页
 
  如果好多内容在你的页面中这时我们就考虑用分页形式来实现显示了。
 
  简单的分页代码:
 
  以下为引用的内容:
  <html>
  <head>
  <title>CuoXIn.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</a><br />
  <a href='index.php?p=Page1'>page 1</a><br />
  <a href='index.php?p=Page2'>page 2</a><br />
  </p></td>
  <td width="360" height="400" valign="top">
  <p>
  <?
  function index()
  {
  echo "<p align=center>Welcome to this tutorial<br />Here you can find funny
  tricks</p><br /><br /><br /><br /><br /><br />"; }
  $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>CuoXIn.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</a><br />
  <a href='index.php?action=contact_us'>page 1</a><br />
  <a href='index.php?action=link_us'>page 2</a><br />
  </p></td>
  <td width="360" height="400" valign="top">
  <p>
  <?
 
  if (isset($_GET['action'])) $PAGE = $_GET['action'];
 
  else $PAGE = 'home';
  switch ($PAGE) {
  //1- index
  case 'home':
  include ('incl/home.php');
  break;
 
  //2-contact form
  case 'contact_us':
  include ('incl/contact_us.php');
  break;
  //3-Link us
  case 'link_us':
  include ('incl/link_us.php');
  break;
  default:
  echo '<p align=center>Error 404! the page you request doesn t exist or as been temporarely unaccessible</p>';
  break;
  }
 
  ?>
 
  </p>
  </td>
  </tr>
  </table>
  </center>
  </body>
  </html>
 
  提供了演示的下载,请自己去试试!
 
  四、页面加载时间的代码
 
  以下为引用的内容:
  <?php
 
  echo ("Page Took :");
  $load = microtime();
  print (number_format($load,2));
  echo (" Sec To Load.");
 
  ?>
 
  五、显示从哪个地址转到你当前访问的站的代码
 
  以下为引用的内容:
  <?php
 
  echo "You Came From:<br />";
  echo $_SERVER['HTTP_REFERER'];
  ?>
 
  六、设置IP地址的转向:屏蔽IP
 
  以下为引用的内容:
  <?php
 
  if(($REMOTE_ADDR == "22.22.22.22")):// ip address
 
  print "<meta http-equiv='refresh' content='0; url=http://www.sina.com'>";// url to redicted
  endif;
  ?>
 
  七、随即显示标题的代码
 
  <Title><?php include("title.php");?></Title>
 
  要事先做一个title.php文件啊
 
  八、如何用PHP来建立一个HTML 的table
 
  以下为引用的内容:
  <?php
  echo"<html>/n";
  echo"<head>/n";
  echo"<title>allo</TITLE>/n";
  echo"</head>/n";
  echo"<body topmargin=/"0/" leftmargin=/"0/" rightmargin=/"0/" bottommargin=/"5/"
  bgcolor=/"#ffffff/">/n";
  echo"<center>/n";
  echo"<table width=/"500/" border=/"1/" cellspacing=/"0/" cellpadding=/"0/">/n";
  echo"<tr>/n";
  echo"<td>/n";
  echo"<p align=/"center/">/n";
  echo"
  /n";
  echo"Text Goes Here/n";
  echo"</p>/n";
  echo"</td>/n";
  echo"</tr>/n";
  echo"</table>/n";
  echo"</center>";
  echo"</body>/n";
  echo"</html>";
  ?>
  九、声明字符串变量
 
  建立一个页面 ( config.php ) 粘贴下面代码
 
  以下为引用的内容:
  <?
  $name="Name";
  $salutation="Hey!";
  $title="CuoXIn.com";
  $copyrights="©2005 CuoXIn.com";
  $link_1="Home";
  ?>
  创建一个页面( test.php )把下列代码
 
  <? include("config.php");?>
 
  放在<html><head>之前,然后在test.php页里来调用上面的字符串
 
  <p align="center"><? echo("$title");?></p>
 
  也可以这样来声明:
 
  以下为引用的内容:
  <?
  $surname1="Marco"; $lastname1="Charette";
  ?>
  调用:
 
  <? echo("$surname1 $lastname1");?>
 
  十、实现页面的跳转:
 
  创建"jump.php"页面并且设置变量来隐藏连接的地址
 
  以下为引用的内容:
  <?
  if ($id == "1"){$link = "http://CuoXIn.com";}
  if ($id == "2"){$link = "http://google.com";}
 
  header("Location: $link"); // 实现了跳转
  exit();
  ?>
 
  保存之后,在另外一个页中加入如下代码:
 
  <a href="jump.php?id=1">Visit This Link</a>
 
  跳转并且还把访客保存在你的页面内:
 
  以下为引用的内容:
  <?
  if ($id == "1"){$link = "http://CuoXIn.com";}
  if ($id == "2"){$link = "http://google.com";}
 
  echo "<frameset rows=/"0,100%/" border=/"0/">/n";
  echo "<frame src=/"jump.php/" name=/"head/" scrolling=/"no/" marginheight=/"0/" frameborder=/"0/" noresize>/n";
  echo "<frame src=/"$link/" name=/"body/" marginheight=/"10/" marginwidth=/"10/" frameborder=/"0/" noresize>/n";
  echo "</frameset>/n";
 
  header("Location: $link");
  exit();
  ?>
 
  保存为jump.php然后再其他页内加入连接代码:
 
  <a href="jump.php?id=1">Visit This Link</a>

(编辑:源码门户网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读