仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 1390|回复: 20
打印 上一主题 下一主题

[学习教程] PHP网页编程之[转]类与PHP (V)

[复制链接]
萌萌妈妈 该用户已被删除
跳转到指定楼层
楼主
发表于 2015-2-4 00:25:37 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
告诉你了一个方式,但是缺少努力这一环节,那也是白搭。   Classes and PHP

Let's do the table body now:

<TR>
<?php

$Tbody->TDOut("Kreisler");
$Tbody->TDOut("Rod");
$Tbody->TDOut("Cortlandt");
$Tbody->TDOut("New York");
$Tbody->TDOut("USA");
?>
</TR>

But this is still getting kind of lengthy. Couldn't we save some more steps? How about trying this:

<?php

function TROut($message) { /*And NO comments about fish, please! ;)   */

        PRINT "<TR>\n";
        $cells=explode("|",$message);
        $iterations=count($cells);
        $i=0;
        while ($i<$iterations) {
                list($message,$span)=explode(":",$cells[$i]);
                if (strlen($message)<1) $message="&nbsp";
                if ($span){
                        $this->TDOut ($message,$span);
                }else{
                        $this->TDOut ($message);
                }
                $i++;
                }
        PRINT "</TR>\n";

}

?>

Wow! That's a little more complicated. Let's break it down:

Line 3 splits the message on pipes and stores the pieces in the array $cells. Line 4 stores the number of items (number of cells) in $iterations. Line 6 begins our loop to go through these cell items. Line 7 splits the cell data at the colon and stores them into the variables $message and $span. Line 8 checks to see if a message was included. If not then it sets message to the default. Line 9 checks to see if there was a span listed (i.e. the cell data had a colon with something behind it. if so, Line 10 calls TDOut with the message and the number of cells it spans. if not, Line 12 calls TDOut with just the message (TDOut will set $colspan to the default 1). Lastly, we close out the row.

What this means is we can pass a single string to TROut that will contain all the necessary information to print out the entire row as long as the string is in the format "celldata[:colspan]|celldata[:colspan]|......celldata[:colspan]".

So, instead of all the work we did before, the headers and body of the table could be called like this:

<TABLE>
<?
$Theader->TROut("Name:2|Address:3");
$Theader->TROut("First|Last|City|State/Province|Country");
$Tbody->TROut("Rod|Kreisler|Cortlandt|New York|USA");
?>
</TABLE>

Wow. That's a lot easier. But what if the data is in variables? Simply join the array:

<?php

$message=join($arry,"|");
$Tbody->TROut($message);

?>

  完成一个功能齐全的动态站点
若天明 该用户已被删除
沙发
发表于 2015-2-4 13:06:52 | 只看该作者
兴趣是最好的老师,百度是最好的词典。
活着的死人 该用户已被删除
板凳
发表于 2015-2-6 15:57:48 | 只看该作者
我要在声明一下:我是个菜鸟!!我对php这门优秀的语言也是知之甚少。但是我要在这里说一下php在网站开发中最常用的几个功能:
愤怒的大鸟 该用户已被删除
地板
发表于 2015-2-7 19:56:41 | 只看该作者
如果你已经到这种程度了,那么你已经可以做我的老师了。其实php也分很多的区域,
金色的骷髅 该用户已被删除
5#
发表于 2015-2-9 23:29:15 | 只看该作者
装在C盘下面可以利用windows的ghost功能可以还原回来(顺便当做是重转啦),当然啦我的编译目录要放在别的盘下,不然自己的劳动成果就悲剧啦。
山那边是海 该用户已被删除
6#
发表于 2015-2-10 13:25:32 | 只看该作者
有位前辈曾经跟我说过,phper 至少要掌握200个函数 编起程序来才能顺畅点,那些不熟悉的函数记不住也要一拿手册就能找到。所以建议新手们没事就看看php的手册(至少array函数和string函数是要记牢的)。
小女巫 该用户已被删除
7#
发表于 2015-2-11 03:54:33 | 只看该作者
Ps:以上纯属原创,如有雷同,纯属巧合
柔情似水 该用户已被删除
8#
发表于 2015-2-17 13:58:12 | 只看该作者
如果你可以写完像留言板这样的程序,那么你可以去一些别人的代码了,
精灵巫婆 该用户已被删除
9#
发表于 2015-3-1 23:56:35 | 只看该作者
找到的的资料很多都是在论坛里的,需要注册,所以我一般没到一个论坛都注册一个id,所有的id都注册成一样的,这样下次再进来的时候就不用重复注册啦。当然有些论坛的某些资料是需要的付费的。
海妖 该用户已被删除
10#
发表于 2015-3-11 01:05:26 | 只看该作者
曾经犯过一个很低级的错误,我在文件命名的时候用了一个横线\\\\\\\'-\\\\\\\' 号,结果找了好几个小时的错误,事实是命名的时候 是不能用横线 \\\\\\\'-\\\\\\\' 的,应该用的是下划线  \\\\\\\'_\\\\\\\' ;
小魔女 该用户已被删除
11#
发表于 2015-3-11 13:14:22 | 只看该作者
我学习了一段时间后,我发现效果并不好(估计是我自身的问题)。因为一个人的精力总是有限的,同时学习这么多,会导致每个的学习时间都得不到保证。
不帅 该用户已被删除
12#
发表于 2015-3-18 12:34:54 | 只看该作者
做为1门年轻的语言,php一直很努力。
只想知道 该用户已被删除
13#
发表于 2015-3-25 19:49:53 | 只看该作者
在学习的过程中不能怕麻烦,不能有懒惰的思想。学习php首先应该搭建一个lamp环境或者是wamp环境。这是学习php开发的根本。虽然网络上有很多集成的环境,安装很方便,使用起来也很稳定、
因胸联盟 该用户已被删除
14#
发表于 2015-3-28 21:58:19 | 只看该作者
写的比较杂,因为我也是个新手,不当至于大家多多指正。
15#
发表于 2015-3-30 10:55:20 | 只看该作者
至于模板嘛,各位高人一直以来就是争论不休,我一只小菜鸟就不加入战团啦,咱们新手还是多学点东西的好。
第二个灵魂 该用户已被删除
16#
发表于 2015-4-1 18:08:48 | 只看该作者
爱上php,他也会爱上你。
灵魂腐蚀 该用户已被删除
17#
发表于 2015-4-20 11:30:43 | 只看该作者
这些都是最基本最常用功能,我们这些菜鸟在系统学习后,可以先对这些功能深入研究。
萌萌妈妈 该用户已被删除
18#
 楼主| 发表于 2015-4-25 22:40:30 | 只看该作者
开发工具也会慢慢的更专业,每个公司的可能不一样,但是zend studio是个大伙都会用的。
若相依 该用户已被删除
19#
发表于 2015-4-27 14:44:01 | 只看该作者
在我安装pear包的时候老是提示,缺少某某文件,才发现 那群extension 的排列是应该有一点的顺序,而我安装的版本的排序不是正常的排序。没办法我只好把那群冒号加了上去,只留下我需要使用的扩展。
透明 该用户已被删除
20#
发表于 2015-5-1 21:11:03 | 只看该作者
环境搭建好,当你看见你的浏览器输出“it works\\\\\\\"时你一定是喜悦的。在你解决问题的时候,我强烈建议多读php手册。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-5-28 03:42

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表