Useful PHP Functions
These are three of my favorite PHP functions. 😀
string file_get_contents ( string $filename [, int $flags [, resource $context [, int $offset [, int $maxlen ]]]] ) – Get the contents of a url.
|// following code will display the contents of the web page http://www.example.com
$url = “http://www.example.com”;
$contents = file_get_contents($url);
bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] ) – Requires an email server. This functions programatically sends an email based on the given parameters.
|// send an email to email@example.com
$subj = “example”;
$message=”this is an email”;
if(mail($to, $subj, $message)) echo “Email was sent”;
else echo “Email sending failed.”;
int fwrite ( resource $handle , string $string [, int $length ] ) – Write something to a file. Note that the file and it’s parent directory should have permissions granted to a user such as “apache” or “www-data”.
|// open a file called test.txt and if it does not exist, attempt to create it; place the pointer at the begining of the file
$handle = fopen(“test.txt”, “a+”);
$data = “I am programatically written.\n”;
I’ll stick with these 3 functions for the meantime. With this though, you can make programs such as:
- A simple email interface. 😀
- A logging system using just the last function
- A proxy browser or something.