<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-23554430</id><updated>2024-02-20T17:00:24.412-08:00</updated><title type='text'>PHP learning experience</title><subtitle type='html'>My personal learning experience on php. Basic php scripting language for beginners</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://php-learning.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/23554430/posts/default?alt=atom'/><link rel='alternate' type='text/html' href='http://php-learning.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Jeff Cai</name><uri>http://www.blogger.com/profile/17737431352557424345</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>12</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-23554430.post-114755202555849004</id><published>2006-05-13T13:22:00.000-07:00</published><updated>2006-05-13T13:27:06.456-07:00</updated><title type='text'>Use PHP Code to Send Email</title><content type='html'>Yesterday, I was assigned an task of creating a contest registration&lt;span style=&quot;font-size: 10.5pt; font-family: &amp;quot;Times New Roman&amp;quot;;&quot; lang=&quot;EN-US&quot;&gt;&lt;/span&gt; page so that when people register, I should get their information and at the same time, the person who register should get an welcome email from me. How can I accomplish that by php?  I know it is a very easy job for a php expert. For me, I am just like all you guys here - a beginner! I start to recall the functions and did some research on the web and finally, I get it done!  Please look at the following code and explanations for this email sending php code:&lt;br /&gt;&lt;br /&gt;First, I think, if I want to send them a welcome email, which is store in my server called &quot;welcome-mail,html&quot;, I should first, tell php find, open and then read the file. So I start by writing the following code:&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: rgb(255, 102, 0);&quot;&gt;// I assigned the filename to a variable to tell php where my file is stored&lt;/span&gt;&lt;br /&gt;$file = &#39;welcome-mail.html&#39;;&lt;br /&gt;&lt;span style=&quot;color: rgb(255, 102, 0);&quot;&gt;// I am telling php to open the file by using the build-in function in php - &quot;fopen&quot;&lt;/span&gt;&lt;br /&gt;$fh = fopen($file, &#39;r&#39;) or die(&#39;Could not open file!&#39;);&lt;br /&gt;&lt;span style=&quot;color: rgb(255, 102, 0);&quot;&gt;// Tell php to read the file it opend in the last step and then assign a variable $data to content of the file&lt;/span&gt;&lt;br /&gt;$data = fread($fh, filesize($file)) or die(&#39;Could not read file!&#39;);&lt;br /&gt;&lt;span style=&quot;color: rgb(255, 102, 0);&quot;&gt;//After reading the content, close the file by using function &quot;fclose&quot;&lt;/span&gt;&lt;br /&gt;fclose($fh);&lt;br /&gt;&lt;br /&gt;Then, I need to retrive the information about my registered user:&lt;br /&gt;$fname = trim($_POST[&#39;fname&#39;]);  &lt;span style=&quot;color: rgb(255, 102, 0);&quot;&gt;//Get the first name of register&lt;/span&gt;&lt;br /&gt;$lname = trim($_POST[&#39;lname&#39;]);  &lt;span style=&quot;color: rgb(255, 102, 0);&quot;&gt;//Get the last name of register&lt;/span&gt;&lt;br /&gt;$mail = trim($_POST[&#39;email&#39;]);   &lt;span style=&quot;color: rgb(255, 102, 0);&quot;&gt;//Get the email of register&lt;/span&gt;&lt;br /&gt;$site = trim($_POST[&#39;website&#39;]);  &lt;span style=&quot;color: rgb(255, 102, 0);&quot;&gt;//Get the web address of register&lt;/span&gt;&lt;br /&gt;$subject=&quot;Thank you for your registration&quot;;   &lt;span style=&quot;color: rgb(255, 102, 0);&quot;&gt;// the subject that the participator see&lt;/span&gt;&lt;br /&gt;$subject_main=&quot;We get another one to join, Rock!&quot;;   &lt;span style=&quot;color: rgb(255, 102, 0);&quot;&gt; // the subject I see&lt;/span&gt;&lt;br /&gt;$name=$fname.&#39; &#39;.$lname;&lt;br /&gt;$mailmessage=&quot;\r\n Name: &quot;.$name.&quot;\r\n Website: &quot;.$site.&quot;\r\n Email Address: &quot;.$mail;&lt;br /&gt;$mailmessage=$data ;    &lt;span style=&quot;color: rgb(255, 102, 0);&quot;&gt;//assign the content of the file to a new variable - &quot;$mailmessage&quot;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Then I am telling php to send the following to different email address, which is to say, send an email to me that tells me there is another person who wants to join the contest and at the same time, send an welcome mail to that new participator.&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: rgb(255, 102, 0);&quot;&gt;// Additional headers&lt;/span&gt;&lt;br /&gt;$headers  = &#39;MIME-Version: 1.0&#39; . &quot;\r\n&quot;;&lt;br /&gt;$headers .= &#39;Content-type: text/html; charset=iso-8859-1&#39; . &quot;\r\n&quot;;&lt;br /&gt;&lt;br /&gt;$headers .= &#39;To: &#39;.$fname.&#39; &#39;.$lname.&#39; &lt;&#39;.$mail.&#39;&gt;&#39; . &quot;\r\n&quot;;&lt;br /&gt;$headers .= &#39;From: Jeff Cai&#39; . &quot;\r\n&quot;;&lt;br /&gt;mail(&#39;mymail.com&#39;, $subject_main, $message, $headers);&lt;br /&gt;mail($mail, $subject, $mailmessage, $headers);&lt;br /&gt;echo &quot;&lt;br /&gt;Thank you for your registration! You will receive an email from us shortly. &lt;br /&gt; &lt;br /&gt;&lt;br /&gt;We will provide you tips on how you can make your chances of winning even better and keep you updated with our contest standings. &quot;;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;To sum up, here is the whole php code:&lt;/span&gt;&lt;br /&gt;&lt;?php&lt;br /&gt;$file = &#39;matt-email.html&#39;;&lt;br /&gt;$fh = fopen($file, &#39;r&#39;) or die(&#39;Could not open file!&#39;);&lt;br /&gt;$data = fread($fh, filesize($file)) or die(&#39;Could not read file!&#39;);&lt;br /&gt;fclose($fh);&lt;br /&gt;$fname = trim($_POST[&#39;fname&#39;]);&lt;br /&gt;$lname = trim($_POST[&#39;lname&#39;]);&lt;br /&gt;$mail = trim($_POST[&#39;email&#39;]);&lt;br /&gt;$site = trim($_POST[&#39;website&#39;]);&lt;br /&gt;$subject=&quot;Thank you for your registration&quot;;&lt;br /&gt;$subject_main=&quot;We get another one to join&quot;;&lt;br /&gt;$name=$fname.&#39; &#39;.$lname;&lt;br /&gt;$mailmessage=&quot;\r\n Name: &quot;.$name.&quot;\r\n Website: &quot;.$site.&quot;\r\n Email Address: &quot;.$mail;&lt;br /&gt;$mailmessage=$data ;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: rgb(255, 102, 0);&quot;&gt;// To send HTML mail, the Content-type header must be set&lt;/span&gt;&lt;br /&gt;$headers  = &#39;MIME-Version: 1.0&#39; . &quot;\r\n&quot;;&lt;br /&gt;$headers .= &#39;Content-type: text/html; charset=iso-8859-1&#39; . &quot;\r\n&quot;;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: rgb(255, 102, 0);&quot;&gt;// Additional headers&lt;/span&gt;&lt;br /&gt;$headers .= &#39;To: &#39;.$fname.&#39; &#39;.$lname.&#39; &lt;&#39;.$mail.&#39;&gt;&#39; . &quot;\r\n&quot;;&lt;br /&gt;$headers .= &#39;From: Jeff Cai&#39; . &quot;\r\n&quot;;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: rgb(255, 102, 0);&quot;&gt;// send an html mail...&lt;/span&gt;&lt;br /&gt;mail(&#39;mymail.com&#39;, $subject_main, $message, $headers);&lt;br /&gt;mail($mail, $subject, $mailmessage, $headers);&lt;br /&gt;echo &quot;&lt;br /&gt;Thank you for your registration! You will receive an email from us shortly. &lt;br /&gt; &lt;br /&gt;&lt;br /&gt;We will provide you tips on how you can make your chances of winning even better and keep you updated with our contest standings.&quot;;&lt;br /&gt;?&gt;</content><link rel='replies' type='application/atom+xml' href='http://php-learning.blogspot.com/feeds/114755202555849004/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/23554430/114755202555849004' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/23554430/posts/default/114755202555849004'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/23554430/posts/default/114755202555849004'/><link rel='alternate' type='text/html' href='http://php-learning.blogspot.com/2006/05/use-php-code-to-send-email.html' title='Use PHP Code to Send Email'/><author><name>Jeff Cai</name><uri>http://www.blogger.com/profile/17737431352557424345</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-23554430.post-114703483583491004</id><published>2006-05-07T13:44:00.000-07:00</published><updated>2006-05-07T13:47:15.843-07:00</updated><title type='text'>PHP Learning - How to Create Password Protected Page</title><content type='html'>Most often, visitors are required to enter username and password to view a page. You can create user auth either with HTTP and Apache or specify in PHP code. Today, let&#39;s take a look how to with HTTP and Apache.&lt;br /&gt;&lt;br /&gt;You use instructions to Apache, called directives, to set up your authentication application. Directives allow you to specify the files that are password-protected and the valid user names and IDs. The simplest way to use Apache directives for authentication is to create a file called .htaccess&lt;br /&gt;&lt;br /&gt;For example, I want to protect my folder called &quot;user&quot;. Thus I will create a file called .htaccess. in that file, I specifies the following lines:&lt;br /&gt;&lt;br /&gt;AuthUserFile c:\secret\.htpass&lt;br /&gt;&lt;br /&gt;AuthGroupFile /dev/null&lt;br /&gt;&lt;br /&gt;AuthName Accounting Department&lt;br /&gt;&lt;br /&gt;AuthType Basic&lt;br /&gt;&lt;br /&gt;Require valid-user&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;then in the Windows command prompt, i can type&lt;br /&gt;&lt;br /&gt;c:\Apache\bin\htpasswd -c c:\secret\.htpass jeff&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;to create a username for Jeff (in order to do this, you need to go to your httpd.txt file and change &quot;AllowOverride None&quot; to &quot;AllowOverride Authconfig&quot;)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Another way to create a page that requires user name and password is through using Http Auth in PHP. Unlike Http auth with Apache, Http auth with PHP have username and password stored in database, in my example, i will use Mysql (since it is my favorite database)&lt;br /&gt;&lt;br /&gt;First, I want to create a database, called &quot;Jefftest&quot;&lt;br /&gt;&lt;br /&gt;Create database Jefftest;&lt;br /&gt;&lt;br /&gt;Then create a table in the database&lt;br /&gt;&lt;br /&gt;CREATE TABLE User (&lt;br /&gt;&lt;br /&gt;user_name CHAR(10) NOT NULL,&lt;br /&gt;&lt;br /&gt;password CHAR(255) NOT NULL,&lt;br /&gt;&lt;br /&gt;create_date DATE NOT NULL,&lt;br /&gt;&lt;br /&gt;PRIMARY KEY(user_name) );&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Then you can access the database from your PHP script with the MySQL functions that are built into PHP. In here, i won&#39;t tell you how to access Mysql by using php built-in function (I might in the future) since it is fairly complex to php beginners. But at least you got the idea of how this function is achieved by using HTTP with the apache server.</content><link rel='replies' type='application/atom+xml' href='http://php-learning.blogspot.com/feeds/114703483583491004/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/23554430/114703483583491004' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/23554430/posts/default/114703483583491004'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/23554430/posts/default/114703483583491004'/><link rel='alternate' type='text/html' href='http://php-learning.blogspot.com/2006/05/php-learning-how-to-create-password.html' title='PHP Learning - How to Create Password Protected Page'/><author><name>Jeff Cai</name><uri>http://www.blogger.com/profile/17737431352557424345</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-23554430.post-114522634520184745</id><published>2006-04-16T15:05:00.000-07:00</published><updated>2006-04-16T15:25:45.216-07:00</updated><title type='text'>PHP Lesson - Basic Programming (1)</title><content type='html'>After talking about basic php components, such as strings, intergers, arrays, let&#39;s move on to inergrate them together and start our basic programming journey.&lt;br /&gt;&lt;br /&gt;First, we begin with setting up conditions. Put into simply words, Conditions are expressions that PHP tests or evaluates to see whether they are true or false. Some common operator often see including:&lt;br /&gt;==         Are the two values equal in value?&lt;br /&gt;=== Are the two values equal in both value and data type?&lt;br /&gt;&gt; Is the first value larger than the second value?&lt;br /&gt;&gt;= Is the first value larger than or equal to the second value?&lt;br /&gt;&lt; Is the first value smaller than the second value?&lt;br /&gt;&lt;= Is the first value smaller than or equal to the second value?&lt;br /&gt;!== Are the two values not equal to each other in either value or data type?&lt;br /&gt;&lt;br /&gt;PHP tests comparisons by evaluating them and returning a Boolean value, either TRUE or FALSE. For example, look at the following comparison:&lt;br /&gt;$a==$b   If $a=1 and $b=1, the comparison returns TRUE. If $a =1 and $b =2, the comparison&lt;br /&gt;returns FALSE.&lt;br /&gt;&lt;br /&gt;Sometimes you just need to know whether a variable exists or what type of data is in the variable. Following are some common ways to test variables:&lt;br /&gt;isset($varname)              # True if variable is set, even if nothing is stored in it.&lt;br /&gt;empty($varname)          # True if value is 0 or is a string with no characters in it or is not set.&lt;br /&gt;is_array($var2): Checks to see if $var2 is an array&lt;br /&gt;is_float($number): Checks to see if $number is a floating point&lt;br /&gt;number&lt;br /&gt;is_null($var1): Checks to see if $var1 is equal to 0&lt;br /&gt;is_numeric($string): Checks to see if $string is a numeric string&lt;br /&gt;is_string($string): Checks to see if $string is a string&lt;br /&gt;&lt;br /&gt;Sometimes you need to compare character strings to see whether they fit&lt;br /&gt;certain characteristics, rather than to see whether they match exact values. For example, when we gather comments from visitors, we want to make sure they are offering a valid email address.  The following are some commonly used special characters that you can use in patterns.&lt;br /&gt;^     Beginning of the line&lt;br /&gt;$     Ending of the line&lt;br /&gt;.      Any single character&lt;br /&gt;?     Preceding character is optional&lt;br /&gt;()    Groups literal characters into grema string that must be matched exactly&lt;br /&gt;[]    A set of optional characters&lt;br /&gt;-     All the characters between two characters&lt;br /&gt;So if we want to validate a user&#39;s mail address, we can use:     ^.+@.+\.com$&lt;br /&gt;The expression ^.+@.+\.com$ matches the string: johndoe@somedomain.com</content><link rel='replies' type='application/atom+xml' href='http://php-learning.blogspot.com/feeds/114522634520184745/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/23554430/114522634520184745' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/23554430/posts/default/114522634520184745'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/23554430/posts/default/114522634520184745'/><link rel='alternate' type='text/html' href='http://php-learning.blogspot.com/2006/04/php-lesson-basic-programming-1.html' title='PHP Lesson - Basic Programming (1)'/><author><name>Jeff Cai</name><uri>http://www.blogger.com/profile/17737431352557424345</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-23554430.post-114472904754718053</id><published>2006-04-10T20:43:00.000-07:00</published><updated>2006-04-10T21:17:46.230-07:00</updated><title type='text'>PHP Learning - View and Modify Arrays</title><content type='html'>In my last lesson, I talked about how to create arrays, and we are going to continue today by starting with the topic of how to view arrays in php, then we will look into how to modify arrays in php.&lt;br /&gt;You can see the structure and values of any array by using one of two&lt;br /&gt;statements — var_dump or print_r. The print_r() statement, however,&lt;br /&gt;gives somewhat less information. To display the $studying_day array, use&lt;br /&gt;the following statement:&lt;br /&gt;print_r($studying_day);   and you will get the output:&lt;br /&gt;Array&lt;br /&gt;(&lt;br /&gt;[1] =&gt; english&lt;br /&gt;[2] =&gt; french&lt;br /&gt;[3] =&gt; math&lt;br /&gt;[4] =&gt; business&lt;br /&gt;)&lt;br /&gt;To get a more detailed information other than the key and value, you can use:&lt;br /&gt;var_dump($studying_day);&lt;br /&gt;&lt;br /&gt;array(3) {&lt;br /&gt;[1]=&gt;&lt;br /&gt;string(7) “english”&lt;br /&gt;[2]=&gt;&lt;br /&gt;string(6) “french”&lt;br /&gt;[3]=&gt;&lt;br /&gt;string(4) “math”&lt;br /&gt;[4]=&gt;&lt;br /&gt;string(8)&quot;business&quot;&lt;br /&gt;}&lt;br /&gt;Arrays can be changed at any time in the script, just as variables can.&lt;br /&gt;Let&#39;s say I am sick of english(actually I am), thus i decided not to study english anymore, then I can use the following statement to remove it from my previously made array:&lt;br /&gt;$studying_day[1] = &quot; &quot;;    # this set the value to empty, but it does not remove&lt;br /&gt;unset(studying_day[1]);  # this statement completely remove it from the group&lt;br /&gt;Sort Array:&lt;br /&gt;One of the most useful features of arrays is that PHP can sort them for you.&lt;br /&gt;To sort my array, I can use the statement: sort($studying_day);&lt;br /&gt;$studying_day[&lt;span style=&quot;font-weight: bold;&quot;&gt;1&lt;/span&gt;]=&quot;english&quot;;&lt;br /&gt;$studying_day[&lt;span style=&quot;font-weight: bold;&quot;&gt;2&lt;/span&gt;]=&quot;french&quot;;&lt;br /&gt;$study_day[&lt;span style=&quot;font-weight: bold;&quot;&gt;3&lt;/span&gt;]=&quot;math&quot;;&lt;br /&gt;$study_day[&lt;span style=&quot;font-weight: bold;&quot;&gt;4&lt;/span&gt;]=&quot;business&quot;;&lt;br /&gt;To sort array that contains word as key, we use asort($arrayname);  for example, we have a new array:&lt;br /&gt;$computer[cpu]=&quot;AMD&quot;;&lt;br /&gt;$computer[mainboard]=&quot;ESC&quot;;&lt;br /&gt;$computer[keyboard]=&quot;BENQ&quot;;&lt;br /&gt;$computer[screen]=&quot;LCD&quot;;&lt;br /&gt;when I use asort($computer), I get the following results:&lt;br /&gt;$computer[cpu]=&quot;&lt;span style=&quot;font-weight: bold;&quot;&gt;A&lt;/span&gt;MD&quot;;&lt;br /&gt;$computer[keyboard]=&quot;&lt;span style=&quot;font-weight: bold;&quot;&gt;B&lt;/span&gt;ENQ&quot;;&lt;br /&gt;$computer[mainboard]=&quot;&lt;span style=&quot;font-weight: bold;&quot;&gt;E&lt;/span&gt;SC&quot;;&lt;br /&gt;$computer[screen]=&quot;&lt;span style=&quot;font-weight: bold;&quot;&gt;L&lt;/span&gt;CD&quot;;&lt;br /&gt;Some other useful sorting include:&lt;br /&gt;rsort($arrayname)   #Sorts by value in reverse order; assigns new numbersas the keys.&lt;br /&gt;ksort($arrayname)   #Sorts by key.&lt;br /&gt;krsort($arrayname)  #Sorts by key in reverse order.&lt;br /&gt;usort($arrayname, function)   #Sorts by a function.</content><link rel='replies' type='application/atom+xml' href='http://php-learning.blogspot.com/feeds/114472904754718053/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/23554430/114472904754718053' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/23554430/posts/default/114472904754718053'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/23554430/posts/default/114472904754718053'/><link rel='alternate' type='text/html' href='http://php-learning.blogspot.com/2006/04/php-learning-view-and-modify-arrays.html' title='PHP Learning - View and Modify Arrays'/><author><name>Jeff Cai</name><uri>http://www.blogger.com/profile/17737431352557424345</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-23554430.post-114462892843204331</id><published>2006-04-09T17:27:00.000-07:00</published><updated>2006-04-09T17:30:27.576-07:00</updated><title type='text'>PHP Learning - Working with Array</title><content type='html'>Starting from today, we are going to work with arrays.&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Arrays&lt;/span&gt; are complex variables that store a group of values under a single&lt;br /&gt;variable name. An array is useful for storing a group of related values.&lt;br /&gt;For example, you can store information about a computer, such as computer case, CPU, memory, and cost, in a single array named $Mycomputerinfo. Information in an array can be handled, accessed, and modified easily.&lt;br /&gt;First, let&#39;s take a look at how to create arrays.&lt;br /&gt;Just like createing variables, to create an array, first, we need to assign values to an array. Let&#39;s say I have a plan for studying different subject, then:&lt;br /&gt;$studying_day[1]=&quot;english&quot;;&lt;br /&gt;$studying_day[2]=&quot;french&quot;;&lt;br /&gt;$study_day[3]=&quot;math&quot;;&lt;br /&gt;$study_day[4]=&quot;business&quot;;&lt;br /&gt;......&lt;br /&gt;if you are crazy about studying, then you can creat along list. We observe the general formating for array is:&lt;br /&gt;$arrayname[key]=&quot;value&quot;;&lt;br /&gt;Array can use either numbers or strings for keys. If you don&#39;t assign any value to the key, for example, if I use $studying_day[]=&quot;english&quot;; then the key will automatically assigned to a value of zero.&lt;br /&gt;We can also use a shortcut for the above array. $studying_day(1=&gt;&quot;english&quot;,&quot;french&quot;,&quot;math&quot;,&quot;business&quot;);&lt;br /&gt;You can also create an array with a range of values by using the following&lt;br /&gt;statement:&lt;br /&gt;$years = range(2001, 2010); the result looks like the following:&lt;br /&gt;$years[0] = 2001&lt;br /&gt;$years[1] = 2002&lt;br /&gt;. . .&lt;br /&gt;$years[8] = 2009&lt;br /&gt;$years[9] = 2010&lt;br /&gt;&lt;br /&gt;In my next &lt;span style=&quot;font-weight: bold;&quot;&gt;php learning lesson&lt;/span&gt;, I am going to talk about how to view arrays.</content><link rel='replies' type='application/atom+xml' href='http://php-learning.blogspot.com/feeds/114462892843204331/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/23554430/114462892843204331' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/23554430/posts/default/114462892843204331'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/23554430/posts/default/114462892843204331'/><link rel='alternate' type='text/html' href='http://php-learning.blogspot.com/2006/04/php-learning-working-with-array.html' title='PHP Learning - Working with Array'/><author><name>Jeff Cai</name><uri>http://www.blogger.com/profile/17737431352557424345</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-23554430.post-114401549311315003</id><published>2006-04-02T13:48:00.000-07:00</published><updated>2006-04-02T15:04:53.146-07:00</updated><title type='text'>PHP Learning - Working with Data(4)</title><content type='html'>PHP provides many built-in functions for manipulating strings. When you want to remove the leading or trailing spaces, you can use the following statement:&lt;br /&gt;$string = trim($string) ;       # removes leading &amp; trailing spaces&lt;br /&gt;$string = ltrim($string) ;      # removes leading spaces&lt;br /&gt;$string = rtrim($string) ;     # removes trailing spaces&lt;br /&gt;&lt;br /&gt;PHP can also help you split a string into words.  The general&lt;br /&gt;form of this function is as follows:&lt;br /&gt;str_word_count(“string”,format);&lt;br /&gt;In this expression, format can be 1, meaning return the words as a numeric&lt;br /&gt;array; or 2, meaning return the words as an array where the key is the position&lt;br /&gt;of the first character of the word. It may be confusing to you at this point, I will explain array in detail in the future of my php lesson.&lt;br /&gt;To give you an example here:&lt;br /&gt;$string = “Counting Words”;&lt;br /&gt;$number of words = str_word_count($string);&lt;br /&gt;$word1 = str_word_count($string,1);&lt;br /&gt;$word2 = str_word_count($string,2);&lt;br /&gt;&lt;br /&gt;if we echo $word1, we get:&lt;br /&gt;$word1[0] = Counting&lt;br /&gt;$word1[1] = Words&lt;br /&gt;if we echo $word2, we get:&lt;br /&gt;$word2[0] = Counting&lt;br /&gt;$word2[9] = Words</content><link rel='replies' type='application/atom+xml' href='http://php-learning.blogspot.com/feeds/114401549311315003/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/23554430/114401549311315003' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/23554430/posts/default/114401549311315003'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/23554430/posts/default/114401549311315003'/><link rel='alternate' type='text/html' href='http://php-learning.blogspot.com/2006/04/php-learning-working-with-data4.html' title='PHP Learning - Working with Data(4)'/><author><name>Jeff Cai</name><uri>http://www.blogger.com/profile/17737431352557424345</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-23554430.post-114393584051514786</id><published>2006-04-01T15:44:00.000-08:00</published><updated>2006-04-01T15:57:20.686-08:00</updated><title type='text'>PHP Learning - Working with Data(3)</title><content type='html'>Use special characters in  strings:&lt;br /&gt;php provides some special characters you can use in string: /n and /t&lt;br /&gt;$string = “NBA \nPlayer”;&lt;br /&gt;echo $string; &lt;br /&gt;you will get the result :&lt;br /&gt;NBA&lt;br /&gt;Player&lt;br /&gt;&lt;br /&gt;$string = “Line 1 \n\tLine 2”;&lt;br /&gt;echo $string;&lt;br /&gt;you will get the result:&lt;br /&gt;Line 1&lt;br /&gt;          Line 2&lt;br /&gt;&lt;br /&gt;These special character can only be used with double quotes, I will explain the differences between single-quoted string and double-quoted string&lt;br /&gt;If you enclose a variable in double quotes, PHP uses the value of the variable.&lt;br /&gt;However, if you enclose a variable in single quotes, PHP uses the literal variable. To illurstrate, see the following example:&lt;br /&gt;$name =&quot;Yao Ming&quot;;&lt;br /&gt;$output1 = &quot;$name&quot;;&lt;br /&gt;$output2 = &#39;$name&#39;;&lt;br /&gt;echo $output1;&lt;br /&gt;echo $output2;&lt;br /&gt;you will get the result&lt;br /&gt;Yao Ming&lt;br /&gt;$name&lt;br /&gt;&lt;br /&gt;Sometimes you want a character in a double-quoted string to be treated as a&lt;br /&gt;literal, not as a special character, even though it has special meaning.&lt;br /&gt;You can tell PHP to output characters, rather than use their special meaning, by preceding&lt;br /&gt;the character with a backslash (\). This is called escaping the character.&lt;br /&gt;For example, the following two strings produce the same output:&lt;br /&gt;$var1=&quot;music&quot;;&lt;br /&gt;$string = &quot;The variable name is \$var1&quot;;&lt;br /&gt;echo $string;&lt;br /&gt;you will get the result:  &quot;The variable name is $var1&quot; instead of &quot;The variable name is music&quot;</content><link rel='replies' type='application/atom+xml' href='http://php-learning.blogspot.com/feeds/114393584051514786/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/23554430/114393584051514786' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/23554430/posts/default/114393584051514786'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/23554430/posts/default/114393584051514786'/><link rel='alternate' type='text/html' href='http://php-learning.blogspot.com/2006/04/php-learning-working-with-data3.html' title='PHP Learning - Working with Data(3)'/><author><name>Jeff Cai</name><uri>http://www.blogger.com/profile/17737431352557424345</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-23554430.post-114368617758312208</id><published>2006-03-29T18:11:00.000-08:00</published><updated>2006-03-29T18:36:17.603-08:00</updated><title type='text'>PHP Learning - Working with Data(2)</title><content type='html'>Use build-in function for simple math calculations:&lt;br /&gt;To compute a square root:  $number=sqrt(91);&lt;br /&gt;Round up to the next interger $number=ceil(27.63);&lt;br /&gt;There are a lot of function help you with calculations, I will not list them here&lt;br /&gt;&lt;br /&gt;Usually, you will want to control how to display the number, then the statement number_format comes into play.&lt;br /&gt;number_format(number,decimals,&quot;decimalsep&quot;,&quot;thousandsep)&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;number&lt;/span&gt; is the number to be formatted. This must always be included.&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;&lt;br /&gt;decimals&lt;/span&gt; is the number of decimal places. If decimals is not included,&lt;br /&gt;the number of decimal places is 0 by default.&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;decimalsep&lt;/span&gt; is the character used to separate the decimal places. The&lt;br /&gt;default is a decimal point. If you include this, you must also include&lt;br /&gt;thousandsep.&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;thousandsep&lt;/span&gt; is the character used to separate the number into thousands.&lt;br /&gt;The default is a comma. If you include this parameter, you must&lt;br /&gt;also include decimalsep.&lt;br /&gt;&lt;br /&gt;For more complicated formatting, you can use the statement &quot;printf&quot; and &quot;sprintf&quot;.</content><link rel='replies' type='application/atom+xml' href='http://php-learning.blogspot.com/feeds/114368617758312208/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/23554430/114368617758312208' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/23554430/posts/default/114368617758312208'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/23554430/posts/default/114368617758312208'/><link rel='alternate' type='text/html' href='http://php-learning.blogspot.com/2006/03/php-learning-working-with-data2.html' title='PHP Learning - Working with Data(2)'/><author><name>Jeff Cai</name><uri>http://www.blogger.com/profile/17737431352557424345</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-23554430.post-114361711845107069</id><published>2006-03-28T23:05:00.000-08:00</published><updated>2006-03-28T23:25:18.470-08:00</updated><title type='text'>PHP learning - Working With Data(1)</title><content type='html'>In previous lesson, we have learned variables. In php, variables can store data in different types. The different types of data are:&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Interger: A whole number (no fractions), such as 10, 0, -43&lt;/li&gt;&lt;li&gt;Floating point number: A number that include decimal places, such as 5.36, 4.232&lt;/li&gt;&lt;li&gt;Character string: A series of single characters, such as &quot;good&quot;, &quot;hello&quot;&lt;/li&gt;&lt;li&gt;Boolean: a true or false value&lt;/li&gt;&lt;/ol&gt;Php is smarter than you think, it evaluate the variable you stored and will assign an approriate data type to the variable. For example:&lt;br /&gt;$number=2 ;  # php store it as interger&lt;br /&gt;$sports=&quot;football&quot; #php store it as character string&lt;br /&gt;&lt;br /&gt;You can also tell php the type of data you want to store, look at the following example:&lt;br /&gt;$number=(int) $var1;  #you are telling php to store $var1 as interger&lt;br /&gt;$sports=(string)$var2; #you are telling php to store $var2 as character string&lt;br /&gt;&lt;br /&gt;To find out the type of a variable, use var_dump:&lt;br /&gt;var_dump($var1)  #you are asking php what type of data is variable1&lt;br /&gt;&lt;br /&gt;PHP provides a shortcut for adding 1 to a variable, for example:&lt;br /&gt;$number=$number+1;   can be rewrite as $number++;&lt;br /&gt;$number=$number-1;    can be rewrite as $number--;&lt;br /&gt;Other forms of shortcut includes:&lt;br /&gt;$number+=3;&lt;br /&gt;$number-=2;&lt;br /&gt;$number*=4;&lt;br /&gt;$number/=5;</content><link rel='replies' type='application/atom+xml' href='http://php-learning.blogspot.com/feeds/114361711845107069/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/23554430/114361711845107069' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/23554430/posts/default/114361711845107069'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/23554430/posts/default/114361711845107069'/><link rel='alternate' type='text/html' href='http://php-learning.blogspot.com/2006/03/php-learning-working-with-data1.html' title='PHP learning - Working With Data(1)'/><author><name>Jeff Cai</name><uri>http://www.blogger.com/profile/17737431352557424345</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-23554430.post-114197201330127207</id><published>2006-03-09T22:01:00.000-08:00</published><updated>2006-03-09T22:26:53.306-08:00</updated><title type='text'>PHP Learning-Work With Constants</title><content type='html'>Constants are similiar to variables, it is created by using &quot;define&quot; statement, such as:&lt;br /&gt;define (&quot;Yao Ming&quot;,&quot;Best NBA Center&quot;);&lt;br /&gt;a number can also be defined&lt;br /&gt;define(&quot;interest&quot;, .02);&lt;br /&gt;&lt;br /&gt;To display constants, we can use &quot;print_r&quot; or &quot;echo&quot; statement&lt;br /&gt;print_r(Yao Ming);&lt;br /&gt;you will get &quot;Best NBA Center&quot;&lt;br /&gt;&lt;br /&gt;Constants are really easy to understand, I will talk about Data in the next php learning session. (Emm, may be you are wondering why today&#39;s lesson is so short......   Take it easy, buddy, we will go through this step by step)</content><link rel='replies' type='application/atom+xml' href='http://php-learning.blogspot.com/feeds/114197201330127207/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/23554430/114197201330127207' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/23554430/posts/default/114197201330127207'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/23554430/posts/default/114197201330127207'/><link rel='alternate' type='text/html' href='http://php-learning.blogspot.com/2006/03/php-learning-work-with-constants.html' title='PHP Learning-Work With Constants'/><author><name>Jeff Cai</name><uri>http://www.blogger.com/profile/17737431352557424345</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-23554430.post-114178657107192151</id><published>2006-03-07T18:56:00.000-08:00</published><updated>2006-03-07T18:56:11.096-08:00</updated><title type='text'></title><content type='html'>&lt;a href=&#39;http://php-learning.blogspot.com/&#39; class=&#39;BlogTitle&#39;&gt;PHP learning experience&lt;/a&gt;&lt;br /&gt;Instruction on php scripts and share my personal php learning experience and steps, good for php beginners. </content><link rel='replies' type='application/atom+xml' href='http://php-learning.blogspot.com/feeds/114178657107192151/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/23554430/114178657107192151' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/23554430/posts/default/114178657107192151'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/23554430/posts/default/114178657107192151'/><link rel='alternate' type='text/html' href='http://php-learning.blogspot.com/2006/03/php-learning-experience-instruction-on.html' title=''/><author><name>Jeff Cai</name><uri>http://www.blogger.com/profile/17737431352557424345</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-23554430.post-114170181984256078</id><published>2006-03-06T18:47:00.000-08:00</published><updated>2006-03-06T19:31:23.570-08:00</updated><title type='text'>PHP Learning basics-PHP variables(1)</title><content type='html'>Basically, variables  in &lt;span style=&quot;font-weight: bold;&quot;&gt;php&lt;/span&gt; are containers that holds information. Variables starts with $, for example, you can name your variable $first_name, $last_name.... Be careful, variables can not start with a number, thus $4name would not be allowed in php as variable.&lt;br /&gt;Some examples of variables:&lt;br /&gt;$price=4;&lt;br /&gt;$name=&quot;Jeff&quot;;&lt;br /&gt;Something worth to notice here, when you assign a variable to a number, you don&#39;t need include &quot;&quot;, however, when you assign variable to a string(I will explain later as we go through php in my blog), you either have to use &quot;&quot; or &#39;&#39;, and a ; is always followed after you name the variable&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: rgb(51, 51, 255);&quot;&gt;To display a variable value&lt;/span&gt;, you can use &quot;echo&quot; or &quot;print_r&quot;, for example:&lt;br /&gt;$popsinger=&quot;Jeff Chang&quot;;&lt;br /&gt;echo $popsinger ;(or print_r ($popsinger);)&lt;br /&gt;For either of the command, you will get result &quot;Jeff&quot;.&lt;br /&gt;Of course, you can use &quot;echo&quot; command print more results once, looking at the example below:&lt;br /&gt;$first_name=&quot;Jeff&quot;;&lt;br /&gt;$last_name=&quot;Chang&quot;;&lt;br /&gt;echo &quot;Pop singer is&quot;, &quot;$first_name,&quot; &quot;, $last_name;&lt;br /&gt;The result will be:  Pop singer is Jeff Chang.&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: rgb(51, 51, 255);&quot;&gt;A little more complicated example&lt;/span&gt;:&lt;br /&gt;$web=&quot;web&quot;;&lt;br /&gt;echo &quot;take a look at this $website&quot;;&lt;br /&gt;What do we do now?   we noticed that the variable &quot;$website&quot; does not even exist here, to tell php that we want to display website, we can use something like&lt;br /&gt;echo &quot;take a look at this {$web}site;   Then you will get the desired result(It is just an example to show you something, of course i know i can just use $website=&quot;website&quot;, lol)&lt;br /&gt;&lt;br /&gt;Look at this:&lt;br /&gt;$name=&quot;NBA player&quot;;&lt;br /&gt;$name=&quot;Yao Ming&quot;&lt;br /&gt;ok, why there is $ here??  if you look carefully, actually, we are creating a new variable here, which is $NBA player=&quot;Yao Ming&quot; &lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: rgb(51, 51, 255);&quot;&gt;To remove a variable, you can use: unset (variablename), such as unset($name), and you can unset more than one at a time, use &quot;,&quot; to separate the variable name, such as unset($name, $NBAplayer)&lt;br /&gt;&lt;/span&gt;Isn&#39;t that easy??  Emm... php language is not scary at all....   I think it is enough for today, we will have fun as we go through php.</content><link rel='replies' type='application/atom+xml' href='http://php-learning.blogspot.com/feeds/114170181984256078/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/23554430/114170181984256078' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/23554430/posts/default/114170181984256078'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/23554430/posts/default/114170181984256078'/><link rel='alternate' type='text/html' href='http://php-learning.blogspot.com/2006/03/php-learning-basics-php-variables1.html' title='PHP Learning basics-PHP variables(1)'/><author><name>Jeff Cai</name><uri>http://www.blogger.com/profile/17737431352557424345</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>