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

sábado, 31 de marzo de 2018

PHP DATE practice 2

<?php

$date = new DateTime('2018/03/29 03:00');   //create  date



echo $date->format('Y-m-d H:i:sP') . "<br><br>";

$date->add(new DateInterval('P30D'));  //add 30 days to the current date


echo $date->format('Y-M-d H:i:sP') . "\n";  print date on  numeric format

echo  "<br><br>";

echo date('l jS \of F Y h:i:s A',time());  // print current date on literal

$date= $date->getTimestamp();  //  convert   a date object to time stamp

echo  "<br><br>";

echo date('l jS \of F Y h:i:s A',$date);   // print the  timestamp of the date object in  literal format


2018-03-29 03:00:00-04:00

2018-Apr-28 03:00:00-04:00

Saturday 31st of March 2018 03:11:52 PM

Saturday 28th of April 2018 03:00:00 AM

http://php.net/manual/en/function.date.php

http://php.net/manual/en/datetime.createfromformat.php

http://php.net/manual/en/datetime.formats.date.php

lunes, 26 de marzo de 2018

array line

<?php
$list=array(1,2,3,4,5,6);

$line=0;
foreach($list as $value){
$line+=1;

if($line>4){
$line=1;
}
echo "$value :$line<br>";


}

?>

1 :1
2 :2
3 :3
4 :4
5 :1
6 :2

lunes, 19 de marzo de 2018

PHP Date Practice

Creating  a date and  adding a  time interval


<?php

$date = new DateTime();



echo $date->format('Y-m-d H:i:sP') . "<br>";

$date->add(new DateInterval('P30D'));  //adding 30  days



echo $date->format('Y-m-d H:i:sP') . "\n";



Object oriented style
<?php
$date 
= new DateTime('2000-01-01');
$date->add(new DateInterval('P10D'));
echo 
$date->format('Y-m-d') . "\n";?>
Procedural style
<?php
$date 
date_create('2000-01-01');
date_add($datedate_interval_create_from_date_string('10 days'));
echo 
date_format($date'Y-m-d');?>

http://php.net/manual/en/datetime.add.php
Formats supported :http://php.net/manual/en/datetime.formats.relative.php
Creating  a  date   using computer time and also specifying time zone

<?php// Specified date/time in your computer's time zone.
$date = new DateTime('2000-01-01');

echo $date->format('Y-m-d H:i:sP') . "\n";

// Specified date/time in the specified time zone.

$date = new DateTime('2000-01-01', new DateTimeZone('Pacific/Nauru'));

echo $date->format('Y-m-d H:i:sP') . "\n";

// Current date/time in your computer's time zone.
$date = new DateTime();

echo $date->format('Y-m-d H:i:sP') . "\n";

// Current date/time in the specified time zone.
$date = new DateTime(null, new DateTimeZone('Pacific/Nauru'));
echo $date->format('Y-m-d H:i:sP') . "\n";

// Using a UNIX timestamp.  Notice the result is in the UTC time zone.
$date = new DateTime('@946684800');
echo 
$date->format('Y-m-d H:i:sP') . "\n";

domingo, 18 de marzo de 2018

printing date and unixtime

$date = date_create();  //create date object based on current date

echo date_format($date, 'Y-m-d H:i:s');  // format and print date

echo "<br>";
echo $date->getTimestamp();  // print the unix time of current date

sábado, 10 de marzo de 2018

IBM tts API

https://michaelheap.com/speech-to-text-with-ibm-watson-and-php/