Calling javascript function from php
I am trying to call a javascript function from php. According
to all of the examples I have been looking at the following should work
but it doesn't. Why not?
|
I am trying to call a javascript function from php. According
to all of the examples I have been looking at the following should work
but it doesn't. Why not?
|
$to_time = strtotime("2008-12-13 10:42:00");
$from_time = strtotime("2008-12-13 10:21:00");
echo round(abs($to_time - $from_time) / 60,2). " minute";
?>
<?php
$date1 = time();
sleep(2000);
$date2 = time();
$mins = ($date2 - $date1) / 60;
echo $mins;
?>
php function to remove special characters
function clean($string) {
$string = str_replace(' ', '-', $string); // Replaces all spaces with hyphens.
return preg_replace('/[^A-Za-z0-9\-]/', '', $string); // Removes special chars.
}
how can I prevent multiple hyphens from being next to each other?
and have them replaced with just 1? Thanks in advance!
function clean($string) {
$string = str_replace(' ', '-', $string); // Replaces all spaces with hyphens.
$string = preg_replace('/[^A-Za-z0-9\-]/', '', $string); // Removes special chars.
return preg_replace('/-+/', '-', $string); // Replaces multiple hyphens with single one.
}
|
It looks like the TZ of your database is set to GMT (UTC), which is as it should be.
You need to convert your local date into GMT when adding to the database.
from the MySQL 5.1
CONVERT_TZ() converts a datetime value dt from time zone given by
from_tz to the time zone given by to_tz and returns the resulting value.Time zones may be specified as described in Section 5.10.8, “MySQL Server Time Zone Support”. This function returns NULL if the arguments are invalid. If the value falls out of the supported range of the TIMESTAMP type when converted fom from_tz to UTC, no conversion occurs. The TIMESTAMP range is described in Section 11.1.2, “Overview of Date and Time Types”.
|
<?php
$a = 1;
while ($a <= 10){
echo $a ."<br/>";
}
?>
<?php
for ($a=1; $a <=10 ; $a++){
echo $a ."<br/>";
}
?>
<?php
for ($a=1; $a <=10 ; $a++){
echo $a ."<br/>";
if($a==5){
break;
}
}
?>
<?php
for ($i = 0; $i < 5; ++$i) {
if ($i == 2)
continue
echo $i;
}
?>
<?php
for ($a =10; $a <= 15; $a++){
echo "First Loop <br/>";
for ($b = 5; $b < 10; $b++){
echo "Second Loop <br/>";
}
}
?>
PHP function to get age for date of birth
function age_from_dob($dob){
$dob = strtotime($dob);
$y = date('Y', $dob);
if (($m = (date('m') - date('m', $dob))) < 0) {
$y++;
} elseif ($m == 0 && date('d') - date('d', $dob) < 0) {
$y++;
}
return date('Y') - $y;
}
echo age_from_dob('2005/04/19'); date in yyyy/mm/dd format.