PHP isn’t rocket science, but at the same time, don’t expect to become an expert in five minutes. If you’re a design-oriented person, you may find it takes time to get used to the way PHP is written. What I like about it very much is that it’s succinct. For instance, in classic ASP, to display each word of a sentence on a separate line, you have to type out all this:
<%@ Language=VBScript %>
<% Option Explicit %>
<%
Dim strSentence, arrWords, strWord
strSentence = "ASP uses far more code to do the same as PHP"
arrWords = Split(strSentence, " ", -1, 1)
For Each strWord in arrWords
Response.Write(strWord)
Response.Write("
")
Next
%>
In PHP, it’s simply
$sentence = 'ASP uses far more code to do the same as PHP';
$words = explode(' ', $sentence);
foreach ($words as $word) {
echo "$word
";
}
?>
That may not seem a big difference, but the extra typing gets very tiresome over a long script. PHP also makes it easy to recognize variables, because they always begin with $.Most of the functions have very intuitive names. For example, mysql_connect() connects you to a MySQL database. Even when the names look strange at first sight, you can often work out where they came from. In the preceding example, explode() “blows apart” text and converts it into an array of its component parts.
Perhaps the biggest shock to newcomers is that PHP is far less tolerant of mistakes than browsers are with XHTML. If you omit a closing tag in XHTML, most browsers will still render the page. If you omit a closing quote, semicolon, or brace in PHP, you’ll get an uncompromising error message.This isn’t just a feature of PHP, but
of all server-side technologies, including ASP, ASP.NET, and ColdFusion. It’s why you need to have a reasonable understanding of XHTML and CSS before embarking on PHP. If the underlying structure of your web pages is shaky to start with, your learning curve with PHP will be considerably steeper.
Thursday, January 15, 2009
How hard is PHP to use and learn?
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment