tailieunhanh - Beginning PHP5, Apache, and MySQL Web Development split phần 2

Giả sử bạn quyết định bạn thực sự không muốn ngày được hiển thị với số không hàng đầu thế giới. May mắn thay, PHP có một giải pháp cho rằng khi định dạng các chức năng ngày. Trong ví dụ này, giá trị và hiển thị của nó là giống hệt nhau, nhưng trong một hệ thống cơ sở dữ liệu điều khiển, | Chapter 2 -----Simpo PDF Merge and Split Unregistered Version - http How It Works When PHP comes across an include line in a script it stops working on the current program and immediately shoots on over to whatever file it s told to include. The server parses that second file and carries the results back to the original file where the parsing continues from where it left off. Suppose you decided you didn t really want the date to be shown with the leading zeros. Luckily PHP has a solution for that when formatting the date function. Make the following change to your file and see what happens div align center font size 4 Welcome to my movie review site font br php echo Today is echo date F j echo echo date Y div Your problem is fixed and it s fixed in all the pages in your site in one fell swoop. Using Functions for Efficient Code As with includes functions make your code and your typing more efficient and easier to debug. Functions are blocks of code that can be called from anywhere in your program. They enable you to execute lines of code without having to retype them every time you want to use them. Functions can help set or update variables and can be nested. You can also set a function to execute only if a certain criterion has been fulfilled. Functions are mini-programs within themselves. They don t know about any other variables around them unless you let the other variables outside the function in through a door called global. You use the global varname command to make an outside variable s value accessible to the function. This does not apply to any values assigned to any variables that are global by default such as _POST _GET and so on. Your function can be located anywhere within your script and can be called from anywhere within your script. Therefore you can list all your commonly used functions at the top of your program and they can all be kept together for easier debugging. Better yet you can put all your functions in a .