domingo, 26 de marzo de 2017

forcing file download mp3 and pdf

<?php


// We'll be outputting a mp3
header('Content-Type: application/mp3');

// It will be called downloaded.mp3
header('Content-Disposition: attachment; filename="downloaded.mp3"');

// The PDF source is in original.mp3
readfile('/var/www/html/20564483.mp3');



?>



<?php// We'll be outputting a PDFheader('Content-Type: application/pdf');
// It will be called downloaded.pdfheader('Content-Disposition: attachment; filename="downloaded.pdf"');
// The PDF source is in original.pdfreadfile('original.pdf');?>

viernes, 24 de marzo de 2017

Difference of days, hours month , year on 2 dates

<?php

$today = date("Y-m-d H:i:s");
$datetime1 = date_create('2017-03-23');
$datetime2 = date_create($today);
$interval = date_diff($datetime1, $datetime2);


echo  " Current time ". $today."<br>";


echo $interval->format('%h hrs')."<br>";

echo $interval->format('%d  days')."<br>";

?>

Current time 2017-03-24 22:13:5922 hrs
1 days



$today = date_create(date("Y-m-d"));
$datetime1 = date_create('2018-12-23');
$datetime2 =date_create($today);
$date1=date_create("2018-12-15");
$diff=date_diff($date1,$today);
 $interval=$diff;


http://php.net/manual/en/dateinterval.format.php

viernes, 10 de marzo de 2017

ctype_digit() example Digits



<?php
$strings = array('1820.20', '10002', 'wsl!12');
foreach ($strings as $testcase) {
    if (ctype_digit($testcase)) {
        echo "The string $testcase consists of all digits.\n";
    } else {
        echo "The string $testcase does not consist of all digits.\n";
    }
}
?>



Example #2 A ctype_digit() example comparing strings with integers
<?php

$numeric_string 
'42';$integer        42;ctype_digit($numeric_string);  // true
ctype_digit($integer);         // false (ASCII 42 is the * character)is_numeric($numeric_string);   // trueis_numeric($integer);          // true?>

domingo, 5 de marzo de 2017

Array elemtns callback function

<?php

function cube($n)
{
    return($n.="Hola");
}

$a = array(1, 2, 3, 4, 5);
$b = array_map("cube", $a);
print_r($b);

?>

Examples ¶

Example #1 array_map() example
<?phpfunction cube($n)
{
    return(
$n $n $n);
}
$a = array(12345);$b array_map("cube"$a);print_r($b);?>
This makes $b have:
Array
(
    [0] => 1
    [1] => 8
    [2] => 27
    [3] => 64
    [4] => 125
)
Example #2 array_map() using a lambda function (as of PHP 5.3.0)
<?php
$func 
= function($value) {
    return 
$value 2;
};
print_r(array_map($funcrange(15)));?>
Array
(
    [0] => 2
    [1] => 4
    [2] => 6
    [3] => 8
    [4] => 10
)

sumando arreglos

<?php

$a = array_fill(5, 6, 'banana');

print_r($a);

echo "<br>";

$a = $a+array_fill(11, 6, 'cocos');



print_r($a);

?>


Array ( [5] => banana [6] => banana [7] => banana [8] => banana [9] => banana [10] => banana )


Array ( [5] => banana [6] => banana [7] => banana [8] => banana [9] => banana [10] => banana [11] => cocos [12] => cocos [13] => cocos [14] => cocos [15] => cocos [16] => cocos )

sábado, 4 de marzo de 2017

php drop down menu

<?php


echo "<select name=numbers>";
$start=0;
while($start!=10){

++$start;

echo   "<option value=$start>$start</option>";

}
END;

 echo "</select>";
?>