This gallery contains 1 photo.
showslow: Fay Ku, See What You Do.
These days I’m concebtration on PHP then desktop developing tools, and I only follow http://php.net/manual/en/index.php for guidance, It has wonderful help tips for beginners. From that I’ve found some very useful PHP fuunctions and I would like to share them with u
Date is very importent part in a web app or widget or just a simple site, so weshould be able to output them in any format we need. These days I was working with a community to develop a prayer times web app for them, This helped me a lot, I can say this function solved 90% of the puzzles I had and helped me well in making of that app. In PHP we can get the time-stamp easily with time() but for customized time and date display we can use this strftime()
strftime("%d %B %Y", time()); // 29 August 2012
This function is used to give a rendom value in an array
$numbers= ["one", "two", "three", "four"];
$x = array_rand($numbers);
You might use rand() or mt_rand() to get a random number, passing 0 and the last index of the array as the min and max parameters; this will give you a random key that you can use to pull a value from your array. Hoe ever this array_rand() is specialized for arrays and quicker then rand() or mt_rand().
The date_default_timezone_set() function sets the default timezone used by all date/time functions.
date_default_timezone_set('Asia/Colombo'); //time zome comes colombo
Here is some useful code to set the default timezone to the user’s local timezone.
$iTime = time();
$arr = localtime($iTime);
$arr += 1900;
$iTztime = gmmktime($arr, $arr, $arr, $arr, $arr, $arr, $arr);
$offset = doubleval(($iTztime-$iTime)/(60*60));
$zonelist = array
'Kwajalein' => -12.00,
'Pacific/Midway' => -11.00,
'Pacific/Honolulu' => -10.00,
'America/Anchorage' => -9.00,
'America/Los_Angeles' => -8.00,
'America/Denver' => -7.00,
'America/Tegucigalpa' => -6.00,
'America/New_York' => -5.00,
'America/Caracas' => -4.30,
'America/Halifax' => -4.00,
'America/St_Johns' => -3.30,
'America/Argentina/Buenos_Aires' => -3.00,
'America/Sao_Paulo' => -3.00,
'Atlantic/South_Georgia' => -2.00,
'Atlantic/Azores' => -1.00,
'Europe/Dublin' => 0,
'Europe/Belgrade' => 1.00,
'Europe/Minsk' => 2.00,
'Asia/Kuwait' => 3.00,
'Asia/Tehran' => 3.30,
'Asia/Muscat' => 4.00,
'Asia/Yekaterinburg' => 5.00,
'Asia/Kolkata' => 5.30,
'Asia/Katmandu' => 5.45,
'Asia/Dhaka' => 6.00,
'Asia/Rangoon' => 6.30,
'Asia/Krasnoyarsk' => 7.00,
'Asia/Brunei' => 8.00,
'Asia/Seoul' => 9.00,
'Australia/Darwin' => 9.30,
'Australia/Canberra' => 10.00,
'Asia/Magadan' => 11.00,
'Pacific/Fiji' => 12.00,
'Pacific/Tongatapu' => 13.00 );
$index = array_keys($zonelist, $offset);
This is derived from PHP manual site.
$message = "Hello Facebook";
echo strip_tags($message); // "Hello Facebook"
Advanced usage is
$message = "<div> This is <strong>my</strong> bio </div>";
echo strip_tags($message, "<strong><em><code>"); // "This is <strong>my</strong> bio"
This is a handy way to check if a variable has been set, use the isset function. We just pass it a variable name, and it will return true if that variable exists, and is set to something other than NULL.
$name = "Joe";
isset($name); // trueisset($age); // false
// get results and display them
// show some default content
Thats all. I hope u could get something from this, alteast boring.. LOL
after a long time spending some time on writing a note, a tech note in fb… this is specially for some one with php knowledge.
Yaa, these days I;m working on php. In the holy ramadhan I spend my time in writing a web component for slmuslims.com people to show the prayer times and an google chrome component to show the same thing in facebook wall.
After a 3 weeks gap, I started developing an email client in php for an idea I got while I was in hispital. My idea id forbidden but I would like to share something about php-email with u.
All I’m shareing because, I had no one to ask help in these topics, except ALLAH, I just google these things and finished my works withthe help pf ALLAH, the almighty. alhamdu lillah 🙂
PHP is always powerful, it has almost all the things in web 2.0 and it comes with mail() which is available in both PHP 4.x and 5.x. This function allows us to send email directly form a script.
mail ( string $to , string $subject , string $message);
this is the basic code to send an email
mail('firstname.lastname@example.org', 'My Subject', 'This is the message');
Actually this is a mail() is a boolean return-type function, which sets TRUE if the mail is sent else it returns FALSE. It is important to note that just because the mail was accepted for delivery, it does NOT mean the mail will actually reach the intended destination.
This mail() in php.net manual comes like this
bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )
the additional_parameters parameter added in php 4.0.5 and the all custom headers like From, Cc, Bcc and Date are supported from php 4.3.0 but only in windows.
A simple example to send mail
// The message
$message = "Line 1nLine 2nLine 3";
// In case any of our lines are larger than 70 characters, we should use wordwrap()
$message = wordwrap($message, 70);
mail('email@example.com', 'My Subject', 'This is the message');
here, we have a 3 line message and if our lines are larger then 70 chars, we opted to use wordwrap(). We can use this or not and use for some more chars also. The final line is the thing.
Send Email from a PHP Script Using SMTP Authentication
To connect to an outgoing SMTP server from a PHP script using SMTP authentication and send an email:
- Make sure the PEAR Mail package is installed.
- Typically, in particular with PHP 4 or later, this will have already been done for you. Just give it a try.
- Adapt the example below for your needs. Make sure you change the following variables at least:
- from: the email address from which you want the message to be sent.
- to: the recipient’s email address and name.
- host: your outgoing SMTP server name.
- username: the SMTP user name (typically the same as the user name used to retrieve mail).
- password: the password for SMTP authentication
Sending Mail from PHP Using SMTP Authentication – Example
$from = "firstname.lastname@example.org ";
$to = "email@example.com";
$subject = "Hi!";
$body = "Hi,nnHow are you?";
$host = "mail.example.com";
$username = "smtp_username";
$password = "smtp_password";
$headers = array ('From' => $from, 'To' => $to, 'Subject' => $subject);
$smtp = Mail::factory('smtp', array ('host' => $host, 'auth' => true, 'username' => $username, 'password' => $password));
$mail = $smtp->send($to, $headers, $body);
echo("" . $mail->getMessage() . "");
echo("Message successfully sent!");
These are the basic things of php mail, I wanted to share. I hope this will help some very beginners a lot.