Archive

Archive for the ‘Php si Mysql’ Category

php explode by multiple delimiters

April 19th, 2011

You need to explode a string by multiple delimiters?

You need to use  the preg_split function. Preg_split is a function  similar to explode.

Explode splits a string by a string, Preg_split splits a string  by a regular expression.

Example

You have a text and you need to explode it by  two strings,  “with” and “and”. Read more…

Php si Mysql ,

Ultima zi a unei luni

March 3rd, 2011

La un moment dat am avut nevoie de o functie care sa afiseze ultima zi a lunii pentru o anumita data.

Cea mai vehiculata functie pe care am gasit-o pe net e asta:

<?php
function lastOfMonth() {
       return date("m/d/Y", strtotime(‘-1 second’,strtotime(‘+1 month’,strtotime(date(‘m’).‘/01/’.date(‘Y’).‘ 00:00:00’))));
}
?>

O solutie mult mai simpla pentru a afla ultima zi din luna pentru o anumita data este:

<?php
function lastDayOfMonth($data){ //$data = "Y-m-d";
        return date("Y-m-t", strtotime($data));
}
?>

Php si Mysql ,