Tutorial Check if File Exists / Append Number to Name

by in , 0

If the file name exists, returns new file name with _number appended so you don't overwrite it.

function file_newname($path, $filename){
    if ($pos = strrpos($filename, '.')) {
           $name = substr($filename, 0, $pos);
           $ext = substr($filename, $pos);
    } else {
           $name = $filename;
    }

    $newpath = $path.'/'.$filename;
    $newname = $filename;
    $counter = 0;
    while (file_exists($newpath)) {
           $newname = $name .'_'. $counter . $ext;
           $newpath = $path.'/'.$newname;
           $counter++;
     }

    return $newname;
}

Example returns:

myfile.jpg
myfile_0.jpg
myfile_1.jpg

Tutorial Change Month Number to Month Name

by in , 0

$monthNum = 5;
$monthName = date("F", mktime(0, 0, 0, $monthNum, 10));

Reference URL

Beautifull HTML5 Love Heart for Valentine, 8 March, Women Gifts

by in , 0

I had to prepare this a few days ago, but I hope that it’s not too late. I want to introduce you the pleasant html5 examples for women, especially on Valentine’s Day, Or 8 March. This is a collection of interactive hearts and flowers. Trust me – your girlfriend will love it!


1. Love Is In The Air

Love Is In The Air

2. Heart Browser

Heart Browser

3. Bliss

Bliss

4. Plasma of love

Plasma of love

5. Love trails

Love trails

6. A Rose is a Rose

A Rose is a Rose

7. Catchy Hearts

Catchy Hearts

8. WebGL Rose

WebGL Rose

9. Love message

Love message

10. Hearts everywhere


Hearts everywhere

Tutorial Change Graphics Based on Season

by in , 0

Function

<?php

function current_season() {
       // Locate the icons
       $icons = array(
               "spring" => "images/spring.png",
               "summer" => "images/summer.png",
               "autumn" => "images/autumn.png",
               "winter" => "images/winter.png"
       );

       // What is today's date - number
       $day = date("z");

       //  Days of spring
       $spring_starts = date("z", strtotime("March 21"));
       $spring_ends   = date("z", strtotime("June 20"));

       //  Days of summer
       $summer_starts = date("z", strtotime("June 21"));
       $summer_ends   = date("z", strtotime("September 22"));

       //  Days of autumn
       $autumn_starts = date("z", strtotime("September 23"));
       $autumn_ends   = date("z", strtotime("December 20"));

       //  If $day is between the days of spring, summer, autumn, and winter
       if( $day >= $spring_starts && $day <= $spring_ends ) :
               $season = "spring";
       elseif( $day >= $summer_starts && $day <= $summer_ends ) :
               $season = "summer";
       elseif( $day >= $autumn_starts && $day <= $autumn_ends ) :
               $season = "autumn";
       else :
               $season = "winter";
       endif;

       $image_path = $icons[$season];

       echo $image_path;
}

?>

Usage

<img src="<?php current_season() ?>" alt="" />

How to strip white space when grabbing text with jQuery

by 0

I'm wanting to use jQuery to wrap a mailto: anchor around an email address, but it's also grabbing the whitepace that the CMS is generating.
Here's the HTML I have to work with, the script as I have it and a copy of the output.
html
<div >
  <div >
    name@example.com    </div>
</div>
jQuery JavaScript
$(document).ready(function(){
  $('div.field-field-email .field-item').each(function(){
    var emailAdd = $(this).text();
      $(this).wrapInner('<a href="mailto:' + emailAdd + '"></a>');
   });
 });
Generated HTML
<div >
  <div ><a href="mailto:%0A%20%20%20%20name@example.com%20%20%20%20">
    name@example.com    </a></div>
</div>
Though I suspect that others reading this question might want to just strip the leading and tailing whitespace, I'm quite happy to lose all the whitespace considering it's an email address I'm wrapping.
Cheers,
Steve

Read more »

jQuery unfocus method?

by in 0

How can I unfocus a textarea or input? I couldn't find a


$('#my-textarea').unfocus(); method?
yes this is the solution:
$('#textarea').blur()

Source

PHP convert Date from dd/mm/yyyy to yyyy-dd-mm

by in , 0

Conversion

$date_array = explode("/",$date); // split the array
$var_day = $date_array[0]; //day seqment
$var_month = $date_array[1]; //month segment
$var_year = $date_array[2]; //year segment
$new_date_format = "$var_year-$var_day-$var_month"; // join them together
Possibly a more MySQL friendly format in some circumstances.

Change period-separated to slash-separated or vice versa (and reverse order)

Convert date from YYYY/MM/DD to DD.MM.YYYY (and from DD.MM.YYYY to YYYY/MM/DD)
/**
 * @param string $date (d.m.y, y-m-d, y/m/d)
 * @return string|bol
 */

function convertDate($date) {
       // EN-Date to GE-Date
       if (strstr($date, "-") || strstr($date, "/"))   {
               $date = preg_split("/[\/]|[-]+/", $date);
               $date = $date[2].".".$date[1].".".$date[0];
               return $date;
       }
       // GE-Date to EN-Date
       else if (strstr($date, ".")) {
               $date = preg_split("[.]", $date);
               $date = $date[2]."-".$date[1]."-".$date[0];
               return $date;
       }
       return false;
}