Showing posts with label SafFunction. Show all posts
Showing posts with label SafFunction. Show all posts

Monday, May 13, 2013

Getting the first letters of text using PHP [SafGetFirstLetters]

It is always better to make small small functions and keep a library, I was collecting all my experimental functions since I am in to PHP.

I wanted to take first letters from a line of text and realized that I have to use this for many places. Yesterday I have made a new one "SafGetFirstLetters"?

What does it do?
Example Text: This Is A Example Text Line
Output: TTIAETL

SafGetFirstLetters("Lagoon Water Villa with Private Pool", 5)
will return: "LWVwP"
5 is the limit of the text I have asked from function to return.

function SafGetFirstLetters($Text,$MaxChr){
 $TextArray = explode(" ",$Text);
 $WordCount = count($TextArray);
 if ($WordCount) {
  $MakeText='';
  for ($i_a = 0; $i_a < $WordCount; $i_a++) {
   $MakeText = $MakeText . substr($TextArray[$i_a],0,1);
  }
 }
 if ($MaxChr) {
  return substr($MakeText,0,$MaxChr);
 }else{
  return $MakeText;
 }
}
If you like it please comment.
Thanks.
Safras Ahamed

Sunday, March 24, 2013

SafSendMailV2: A function to send mail using php

I started to make and collect my own function since 2001 and SafSendMail I made it in 2002 for a project where there was lots of mail sending option. If I want to send a mail I have to write whole lot and I didn't like it. Created SafSendMail so that I can send mail as I want using a single line.

Later I made SafSendMailV2 supporting HTML and other stuff as you can see, if any mail sent using V2 it will also record From-IP & From-File. Using this you can Identify different things.




function SafSendMailV2(
 $MYRECIPIENTE_EMAIL,
 $MYRECIPIENTE_NAME,
 $MYFROM_NAME,
 $MYFROM_EMAIL,
 $MYSUBJECT,
 $MYBODY,
 $MYHTML,
 $REMOTE_ADDR,
 $PHP_SELF){
 $MYRECIPIENTE_EMAIL  = "$MYRECIPIENTE_EMAIL";
 if ($MYHTML==true) {
  $MYHEADERS = "From: $MYFROM_NAME <$MYFROM_EMAIL>\r\n";
  $MYHEADERS .= "MIME-Version: 1.0\r\n";
  $MYHEADERS .= "Content-Type: text/html; charset=windows-1256\r\n";
  $MYHEADERS .= "Content-Transfer-Encoding: base64\r\n";
  $MYHEADERS .= "From-IP: $REMOTE_ADDR\r\n";
  $MYHEADERS .= "From-File: $PHP_SELF\r\n";
  $MYHEADERS .= chunk_split(base64_encode("$MYBODY"));
  mail("$MYRECIPIENTE_EMAIL", "$MYSUBJECT", "", $MYHEADERS);
 }else{
  $MYHEADERS = "From: $MYFROM_NAME <$MYFROM_EMAIL>\r\n";
  $MYHEADERS .= "From-IP: $REMOTE_ADDR\r\n";
  $MYHEADERS .= "From-File: $PHP_SELF";
  mail("$MYRECIPIENTE_EMAIL", "$MYSUBJECT", "$MYBODY", $MYHEADERS);
 }
}

How to use?
SafSendMailV2("Recipiente@domain.com","Recipiente Name","Your Name","Your Email","Subject",$MYBODY,true,$REMOTE_ADDR,$PHP_SELF)

Friday, March 22, 2013

PHP Date Functions with SafDate Functions

This is a set of small functions I use, this will make my life easy, no need to remember all the variables at date() function and you can make some predefined functions that you use always.













saf.date.functions.php
<?php
//Pass 2007-01-22 as date and output  as January 22, 2007
function SafDate1V2($date){
    list($y,$m,$d) = explode("-",$date);
    $mycooldate = date("F d, Y",mktime(0, 0, 0, $m, $d, $y));
    return $mycooldate;
}
//Pass 2007-01-22 as date and output  as Jan 22, 2007
function SafDate2V2($date){
    list($y,$m,$d) = explode("-",$date);
    $mycooldate = date("M d, Y",mktime(0, 0, 0, $m, $d, $y));
    return $mycooldate;

}
//Pass 2007-01-22 as date and output  as Jan 22, 07
function SafDate3V2($date){
    list($y,$m,$d) = explode("-",$date);
    $mycooldate = date("M d, y",mktime(0, 0, 0, $m, $d, $y));
    return $mycooldate;
}
//Pass 2007-01-22 as date and output as Sunday Jan 22, 2007
function SafDate4V2($date){
    list($y,$m,$d) = explode("-",$date);
    $mycooldate = date("l M d, Y",mktime(0, 0, 0, $m, $d, $y));
    return $mycooldate;
}
?>
<?php
//Pass 2007-01-22 as date and output as Sun, Jan 22, 2007
function SafDate5V2($date){
    list($y,$m,$d) = explode("-",$date);
    $mycooldate = @date("D, M d, Y",mktime(0, 0, 0, $m, $d, $y));
    return $mycooldate;
}
?>