Before, I start And you start reading after my End, Let me tell you before you come to this post, You must know Basic of PHP Which includes, Knowing of Variables, Loops, arrays, Forms, GET & POST. If Yes, Than Chhers Let read this further to know more About PHP.
Format
"format" is parameter and it is Required.It Specifies the format of the timestamp.
"timestamp" is parameter and it is optional. Specifies a timestamp. Default is the current date and time
Time PHP Code "PHP Date()" - Format the Date
PHP Date() - Adding a Timestamp
Format
Example
You have Learn Date Function, Now Lets move on to
Let us first now feature of this function, this is time saving feature in short what it does, it calls up some file to execute by just writing the page name, and we don't have to write same code what we have written earlier. For E.g, If we need header in our all page than we can make one header file and will call that page by just writing header tag on every page, rather than typing again and again the header page content, Thats it, If you understood well and goo, if not dont reply here for this function
PHP include function
Examples will make you clear no more Clarification:-
PHP require() Function
Now Let it make it shorter, just write "require" in place of "include" and you are done with require functio too.
Now, You must be thinking why two function for 1 purpose. Nah Nah, Not 1 feature,
Difference in "include()" & "require()" function is, :-
"include()" function executes the bottom line of statement if there is any error line above to it.
But "require()" function stops and does not proceed further, if there is any error in above lines of code/statement.
Rest they both are same.Now Lets move on to
How to open a File
Format
$file = variable and
fopen is function
with "welcome.txt" file name to open and
"r" to format of open, whether readable or writable or executable or two of any of them or all of them.
List of format of open, are
1). "r" = read only and this starts @ the beginning of file.
2). "r+" = read and write, starts @ beginning of file.
3). "w" = write only, Opens the file and clears it, if the filename doesnot exist than it will create it.
4). "w+" = write/read starts, Opens the file and clears it, if the filename doesnot exist than it will create it.
5). "a" = Append.Opens and writes to the end of the file or creates a new file if it doesn't exist.
6). "a+" = Read/Append. Preserves file content by writing to the end of the file.
7). "x" = Write only. Creates a new file. Returns FALSE and an error if file already exists.
8). "x+" = Read/Write. Creates a new file. Returns FALSE and an error if file already exists.
ExampleClosing a file
Check End-of-file
Reading a File Line by Line
while is loop here and (!feof($file)) means run the loop until you reach the end of line. [if not feof than echo, if feof than stop]
Reading a File Character by Character
This is for those who will copy my this thread
Index
- PHP Date
- PHP Include
- PHP File
1). PHP Date
Format
PHP Code:
date(format,timestamp)
"format" is parameter and it is Required.It Specifies the format of the timestamp.
"timestamp" is parameter and it is optional. Specifies a timestamp. Default is the current date and time
Time PHP Code "PHP Date()" - Format the Date
Click to View Example (Click to View)
Format
PHP Code:
mktime(hour,minute,second,month,day,year,is_dst)
Example
Click to View (Click to View)

PHP include() & require() function
Let us first now feature of this function, this is time saving feature in short what it does, it calls up some file to execute by just writing the page name, and we don't have to write same code what we have written earlier. For E.g, If we need header in our all page than we can make one header file and will call that page by just writing header tag on every page, rather than typing again and again the header page content, Thats it, If you understood well and goo, if not dont reply here for this function

PHP include function
Examples will make you clear no more Clarification:-
Example (Click to View)
Now Let it make it shorter, just write "require" in place of "include" and you are done with require functio too.
Now, You must be thinking why two function for 1 purpose. Nah Nah, Not 1 feature,
Difference in "include()" & "require()" function is, :-
"include()" function executes the bottom line of statement if there is any error line above to it.
But "require()" function stops and does not proceed further, if there is any error in above lines of code/statement.
Rest they both are same.Now Lets move on to
PHP File
How to open a File
Format
PHP Code:
<html>
<body>
<?php
$file=fopen("welcome.txt","r");?>
</body>
</html>
$file = variable and
fopen is function
with "welcome.txt" file name to open and
"r" to format of open, whether readable or writable or executable or two of any of them or all of them.
List of format of open, are
1). "r" = read only and this starts @ the beginning of file.
2). "r+" = read and write, starts @ beginning of file.
3). "w" = write only, Opens the file and clears it, if the filename doesnot exist than it will create it.
4). "w+" = write/read starts, Opens the file and clears it, if the filename doesnot exist than it will create it.
5). "a" = Append.Opens and writes to the end of the file or creates a new file if it doesn't exist.
6). "a+" = Read/Append. Preserves file content by writing to the end of the file.
7). "x" = Write only. Creates a new file. Returns FALSE and an error if file already exists.
8). "x+" = Read/Write. Creates a new file. Returns FALSE and an error if file already exists.
Example
Spoiler (Click to View)
PHP Code:
<?php
$file = fopen("test.txt","r");
//some code to be executed
fclose($file);?>
Check End-of-file
PHP Code:
if (feof($file)) echo "End of file";
Reading a File Line by Line
PHP Code:
<?php
$file = fopen("welcome.txt", "r") or exit("Unable to open file!");//Output a line of the file until the end is reachedwhile(!feof($file))
{
echo fgets($file). "<br />";
}fclose($file);?>
while is loop here and (!feof($file)) means run the loop until you reach the end of line. [if not feof than echo, if feof than stop]
Reading a File Character by Character
PHP Code:
<?php
$file=fopen("welcome.txt","r") or exit("Unable to open file!");
while (!feof($file))
{
echo fgetc($file);
}fclose($file);?>
This is for those who will copy my this thread
Spoiler (Click to View)
No comments:
Post a Comment