sábado, 14 de abril de 2018

php xml

https://stackoverflow.com/questions/35223926/class-simplexmlelement-not-found-on-puphpet-php-5-6


The problem was that I was using Cent OS and in this Linux Distribution, the php-libxml package does not come as default.

I ended up generating a new machine through PuPHPet GUI and added to the System Package the following packages to be installed:

php-xml, php-simplexml
Problem solved.

For those using PHP 7 and Ubuntu, @MPS solved it by running apt-get install php7.0-xml and service apache2 restart.


Or  running apt-get install php7.1-xml 
On Centos, we need to install the XML php package. You can try yum install php56w-xml or yum install php70w-xml if you're using php70w repository for PHP 7.0

viernes, 13 de abril de 2018

setting specific time based on the day of the week

If day it is saturday or sunday set the time to 00
<?php


$start='2018-04-01';

$end=30;

$arr=array();
$ini=1;
while($ini<=$end) {
$date = new DateTime("2018-04-$ini 03:00");

$timestamp= $date->getTimestamp();
$dayname=getdate($timestamp);
if($dayname['weekday']=='Saturday' or $dayname['weekday']=='Sunday' ){
$date = new DateTime("2018-03-$ini 00:00");

}
$arr[]=$date->format('Y-m-d H:i:s');

//echo $date->format('Y-m-d H:i:s') . "<br><br>";
$ini++;
}


foreach($arr as $key=>$value){
echo "$key=>$value<br>";

}
?>

0=>2018-03-01 00:00:00
1=>2018-04-02 03:00:00
2=>2018-04-03 03:00:00
3=>2018-04-04 03:00:00
4=>2018-04-05 03:00:00
5=>2018-04-06 03:00:00
6=>2018-03-07 00:00:00
7=>2018-03-08 00:00:00
8=>2018-04-09 03:00:00
9=>2018-04-10 03:00:00
10=>2018-04-11 03:00:00
11=>2018-04-12 03:00:00
12=>2018-04-13 03:00:00
13=>2018-03-14 00:00:00
14=>2018-03-15 00:00:00
15=>2018-04-16 03:00:00
16=>2018-04-17 03:00:00
17=>2018-04-18 03:00:00
18=>2018-04-19 03:00:00
19=>2018-04-20 03:00:00
20=>2018-03-21 00:00:00
21=>2018-03-22 00:00:00
22=>2018-04-23 03:00:00
23=>2018-04-24 03:00:00
24=>2018-04-25 03:00:00
25=>2018-04-26 03:00:00
26=>2018-04-27 03:00:00
27=>2018-03-28 00:00:00
28=>2018-03-29 00:00:00
29=>2018-04-30 03:00:00