php php练习
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/441087/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
php exercises
提问by Georg Sch?lly
I'm looking for exercises that will help me to learn php (complex loops, arrays, tricks etc)
我正在寻找有助于我学习 php 的练习(复杂循环、数组、技巧等)
回答by Ross
I follow the 'learn by doing' mentality - choose a project and work on it.
我遵循“边做边学”的心态——选择一个项目并致力于它。
Here's a list of small (to medium) projects to try.
这是要尝试的小型(到中型)项目的列表。
List files in a directory
列出目录中的文件
Create a CLI-run and a web-interface tool to list files in directories. Also try navigating the sub-directories and returning information about files (or even showing the contents of them).
创建 CLI 运行和 Web 界面工具以列出目录中的文件。还可以尝试导航子目录并返回有关文件的信息(甚至显示它们的内容)。
Good for traversing arrays and file information. Hints: glob, FileInfo.
适合遍历数组和文件信息。提示:glob,FileInfo。
Parse an XML file
解析 XML 文件
Learn how to read parts of an XML file using SimpleXML. Very easy way to learn to use objects.
了解如何使用 SimpleXML 读取 XML 文件的一部分。学习使用对象的非常简单的方法。
Create some dynamic images
创建一些动态图像
A fun project you can do in an afternoon - display the current date and time on an image, or the viewer's hostname and IP. For extra credit create an object-oriented wrapper for GD (since PHP doesn't have one yet) that generates the image - and then extend it so that themes can be used.
一个可以在下午完成的有趣项目 - 在图像上显示当前日期和时间,或查看者的主机名和 IP。为了获得额外的荣誉,为 GD 创建一个面向对象的包装器(因为 PHP 还没有)来生成图像 - 然后扩展它以便可以使用主题。
Good for learning about GD, superglobals and object-oriented classes.
非常适合学习 GD、超全局变量和面向对象的类。
Build a (small) Twitter application
构建一个(小)Twitter 应用程序
Use the Twitter APIand cURLto read data from the Twitter API (and even post things if you're adventurous). Learn to use other APIs as well (Digg's a good start).
使用Twitter API并cURL从 Twitter API 读取数据(如果您喜欢冒险,甚至可以发布内容)。学习使用其他 API(Digg 是一个好的开始)。
Good for learning to use cURL, web APIs and forms.
适合学习使用cURL、Web API 和表单。
Build a notebook/todo list
建立一个笔记本/待办事项列表
Build a simple todo list application. A nice opportunity to practice some AJAX as well.
构建一个简单的待办事项列表应用程序。也是练习一些 AJAX 的好机会。
Build an image/file upload site
建立一个图像/文件上传站点
Make a simple site (like imageshack or rapidshare) that allows you to upload an image. Show the last 5 uploaded images below the form.
制作一个允许您上传图像的简单网站(如imageshack 或rapidshare)。在表格下方显示最近上传的 5 张图片。
Hints: Handling file uploads, FileInfo.
提示:处理文件上传,FileInfo。
Get friends to break your stuff
让朋友打破你的东西
I think that the best way to initally learn about web security is to do so on a small, throw-away application, and reactively.
我认为初步了解网络安全的最好方法是在一个小的、一次性的应用程序上进行,并且是被动的。
Get some knowledgeable friends to attack your application and seal vulnerabilities as they occur. Get them to help out if you're stuck and to review your security measures to see if you missed anything out. Some basics to learn about:
找一些知识渊博的朋友来攻击你的应用程序并在它们发生时密封漏洞。如果您遇到困难,请让他们提供帮助,并检查您的安全措施,看看您是否遗漏了任何内容。要了解的一些基础知识:
- SQL injection (easy to prevent, common flaw)
- XSS injection
- Scripting injection (never
evaluser input without extremely good reason!)
- SQL注入(容易防范,常见缺陷)
- XSS 注入
- 脚本注入(不要在
eval没有非常充分的理由的情况下进行用户输入!)
Create some sort of CMS
创建某种 CMS
This can be as large or as small as you want it to be: a simple news reporting form to a personal blog. Make sure it includes user accounts and some sort of external user input (e.g. comments). Once you've got a basic system worked out try thinking about how it could be run by other people. Things to think about here:
这可以是您想要的大或小:一个简单的个人博客新闻报道表格。确保它包括用户帐户和某种外部用户输入(例如评论)。一旦你制定了一个基本的系统,试着考虑其他人如何运行它。这里需要考虑的事情:
- DAL (Database Access Layer - make it work on several database platforms)
- Templating
- DAL(数据库访问层 - 使其在多个数据库平台上工作)
- 模板制作
I highly recommend looking at other applications at this point. phpBB3 and vBulletin are good choices for PHP (phpBB is open source but vBulletin is a private product unfortunately). Some say Wordpress is a good thing to look at (I disagree) but I expect Joomla wouldn't be a bad place to look either.
我强烈建议此时查看其他应用程序。phpBB3 和 vBulletin 是 PHP 的不错选择(phpBB 是开源的,但不幸的是 vBulletin 是私有产品)。有人说 Wordpress 是个好东西(我不同意),但我希望 Joomla 也不会是一个糟糕的地方。
Build a cacheable feed reader
构建可缓存的提要阅读器
Slightly more advanced - build a system that reads feeds, stores their contents and returns the data. Then work in caching to the system (e.g. store serialized data about feeds returned (since they won't be changed).
稍微高级一点 - 构建一个系统来读取提要、存储其内容并返回数据。然后缓存到系统中(例如存储有关返回的提要的序列化数据(因为它们不会被更改)。
Good for learning about database interactivity and caching content. Hints: serialize (or even memcached).
非常适合了解数据库交互性和缓存内容。提示:序列化(甚至是 memcached)。
回答by Georg Sch?lly
Everything else you should learn while doing something. Choose something you want to create and learn php along the way.
在做某事时你应该学习的其他一切。选择您想要创建的内容并在此过程中学习 php。
回答by jn2
We have just lauched a site with 26 PHP exercises, beginner to intermediate. It covers variables, control structures, forms, arrays and functions among other things. You start with the problem, then click a button to see the answer script code. Along with the answer script is a link to the output of the answer code. Come see at phpexercises.com.
我们刚刚推出了一个包含 26 个 PHP 练习的网站,从初级到中级。它涵盖了变量、控制结构、表单、数组和函数等。您从问题开始,然后单击一个按钮以查看答案脚本代码。与答案脚本一起是指向答案代码输出的链接。来phpexercises.com 看看。
回答by Aaron Maenpaa
Project Euleris language agnostic, but gives a set of problems to tackle while you learn the language.
Project Euler与语言无关,但会在您学习语言时提供一系列问题来解决。
回答by Andrei Serdeliuc ?
Take a poem and:
拿一首诗,然后:
- capitalize every vowel
- lower case every consonant
- list every other line
- 大写每个元音
- 小写每个辅音
- 每隔一行列出
And another one:
还有一个:
Get the total number of days in a date range (i.e.: 2008-01-01 to 2011-06-23) without using any php date functions.
在不使用任何 php 日期函数的情况下获取日期范围内的总天数(即:2008-01-01 到 2011-06-23)。
回答by RSlaughter
The following page has15 Exercises for Learning a new Programming Language
下一页有15个学习新编程语言的练习
回答by Ronald Conco
The easiest way to learn any language is not necessary to do with tutorials but rather use the language in an actual project. This means creating your own project if you have to and the logic required to accomplish such a project is what expands your php. This gives you the ability to think in PHP.......
学习任何语言的最简单方法不一定是教程,而是在实际项目中使用该语言。这意味着如果必须,请创建您自己的项目,并且完成此类项目所需的逻辑是扩展您的 php.ini 的原因。这使您能够在 PHP 中思考......
e.g. 1)to test fundamentals...create a blog which allows users accounts and admin panel
例如 1) 测试基本原理...创建一个博客,允许用户帐户和管理面板
2)to test email....create a mail listing which people can subscribe and get emails...
and etc.....I can only think of that for now....
等等......我现在只能想到......

