Tuesday, August 25, 2009

File_Get_Contents replacement (CURL)

Some servers have file_get_contents function disabled. But don't worry, most of them have curl library installed. Here is a replacement function for file_get_contents, using CURL library. Easy and working:

  1. function file_get_contents_curl($url) {
  2. $ch = curl_init();
  3. curl_setopt($ch, CURLOPT_HEADER, 0);
  4. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  5. curl_setopt($ch, CURLOPT_URL, $url);
  6. $data = curl_exec($ch);
  7. curl_close($ch);
  8. return $data;
  9. }



Using this function is easy, just like file_get_contents function :

$contents = file_get_contents_curl( 'http://...');

Tuesday, August 4, 2009

PHPMailer UTF-8 messages

Sending UTF-8 body messages with PHPMailer is pretty easy. You just have to set charset

Here is an example: $mail->CharSet = 'UTF-8';

So now you can send utf-8 mail messages using PHPMailer. Good luck.