« Home « Kết quả tìm kiếm

PHP Tutorial - Learn PHP


Tóm tắt Xem thử

- Begin to understand the working model of PHP, so you may begin to design your own PHP projects.Give you a solid base in PHP, so as to make you more valuable in the eyes of future employers.PHP stands for PHP Hypertext Preprocesso..
- If you have PHP inserted into your HTML and want the web browser to interpret it correctly, then you must save the file with a .php extension, instead of the standard .html extension.
- Instead of index.html, it should be index.php if there is PHP code in the file..
- helloworld.php) and place it on PHP enabled server and load it up in your web browser, then you should see "Hello World!".
- echo "Hello World! ";.
- echo "Hello World!".
- echo "Hello World!";.
- at the beginning of the string and closed it at the end of the string.
- Remember to use double-quotes, single-quotes will not grab the value of the string.
- You have already seen the string concatenation operator ".".
- As we have already seen in the Echo Lesson , the period ".".
- echo "<br />.
- echo "Hello World!".
- A common practice for naming files that are to be included is to use the ".php".
- Since we want to create a common menu let's save it as "menu.php"..
- menu.php Code:.
- <a href="http://www.example.com/index.php">Home</a>.
- <a href="http://www.example.com/about.php">About Us</a>.
- <a href="http://www.example.com/links.php">Links</a>.
- <a href="http://www.example.com/contact.php">Contact Us</a>.
- Save the above file as "menu.php".
- Now create a new file, "index.php".
- "menu.php".
- index.php Code:.
- <?php include("menu.php".
- And we would do the same thing for "about.php links.php", and "contact.php".
- You would have to go in and manually edit every single file to add this new page, but with include files you simply have to change "menu.php".
- If we were to use the include command to insert a menu on each of our web pages, what would the visitor see if they viewed the source of "index.php"? Well, because the include command is pretty much the same as copying and pasting, the visitors would see:.
- View Source of index.php to a Visitor:.
- <a href="index.php">Home</a>.
- <a href="about.php">About Us</a>.
- <a href="links.php">Links</a>.
- <a href="contact.php">Contact Us</a>.
- It is often best to use the require command instead of the include command in your PHP Code.
- include("noFileExistsHere.php");.
- Warning: main(noFileExistsHere.php): failed to open stream: No such file or directory in /home/websiteName/FolderName/tizagScript.php on line 2 Warning: main.
- Failed opening 'noFileExistsHere.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in .
- /home/websiteName/FolderName/tizagScript.php on line 2.
- require("noFileExistsHere.php");.
- Warning: main(noFileExistsHere.php): failed to open stream: No such file or directory in /home/websiteName/FolderName/tizagScript.php on line 2.
- Failed opening required 'noFileExistsHere.php' .
- (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/websiteName/FolderName/tizagScript.php on line 2 .
- An if statement is made up of the keyword "if".
- Remember to review HTML Forms if you do not understand any of the above HTML code.
- <form action="process.php".
- is complete, let us continue on and create the "process.php".
- The name of this file is "process.php"..
- process.php Code:.
- ".<br />";.
- and "process.php".
- If someone selected the item brushes and specified a quantity of 6, then the following would be displayed on "process.php":.
- We added two attributes to the form tag to point to "process.php".
- We had "process.php".
- In the above example we made use of the key / value structure of an array.
- The basic structure of the for loop is as follows:.
- Here is the example of the brush prices done with a for loop.
- loop is a slightly modified version of the while loop.
- This HTML code specifies that the form data will be submitted to the "process.php".
- Now that you know about associative arrays, the PHP code from "process.php".
- The get method is different in that it passes the variables along to the "process.php".
- web page by appending them onto the end of the URL.
- Now that we changed the method of sending information on "order.html", we must change the "process.php".
- "magic-quotes.php".
- magic­quotes.php Code:.
- echo "Altered Text: ".$_POST['question'];.
- First, we must supply it with the name of the file that we want it to open.
- The file pointer begins at the front of the file..
- In addition, the data in the file is erased and you will begin writing data at the beginning of the file.
- The file pointer begins at the start of the file..
- However, the data in the file is preserved and you begin will writing data at the end of the file.
- The file pointer begins at the end of the file..
- When you open a file for reading, the file pointer begins at the start of the file.
- This makes sense because you will usually be reading data from the front of the file..
- The file pointer is at the beginning of the file..
- This is exactly the same as r+, except that the file pointer is at the end of the file..
- Replace the (X) with one of the options above (i.e.
- Contents of the testFile.txt File:.
- If you wanted to read all the data from the file, then you need to get the size of the file.
- Now the entire contents of the testFile.txt file is stored in the string variable $theData..
- If we were to write to the file it would begin writing data at the end of the file..
- The contents of the file testFile.txt would now look like this:.
- action="uploader.php".
- After the user clicks submit, the data will be posted to the server and the user will be redirected to uploader.php.
- PHP - File Upload: uploader.php.
- When the uploader.php file is executed, the uploaded file exists in a temporary storage area on the server.
- NOTE: You will need to create a new directory in the directory where uploader.php resides, called.
- echo "The file ".
- echo "<br />The position of the second 5 was $fivePos2";.
- Check the rest of the string for 5's.
- A negative value specifies the number of characters from the end of the string..
- If no length is specified then the end of the string is used.
- Imagine that you want to get rid of those ugly pseudo references (ABC123, DEF321) at the beginning and end of the string.
- d: The day of the month.
- echo "Tomorrow is ".date("m/d/y", $tomorrow).
- d: Day of the month with leading zeroes.
- j: Day of the month without leading zeroes.
- D: Day of the week abbreviations.
- l: Day of the week.
- w: Day of the week without leading zeroes.
- z: Day of the year without leading zeroes

Xem thử không khả dụng, vui lòng xem tại trang nguồn
hoặc xem Tóm tắt