I contact another website by get and get the result of a xml to interprete.
I contact like this:
$v= file_get_contents(
"https://www.v.com/fechasexcursion.php?
agent=M&password=s&fecha1=2018-10-05&fecha2=2018-12-
31&idmodelo=$cifraexcursion");
Then I parse the information to get the dates from the xml to disable these dates in datepicker:
$cifraexcursion = 9;
$xml = new SimpleXMLElement($v);
foreach ($xml->excursion as $tour) {
if ($nameoftour->idmodelo == $cifraexcursion) {
echo "<br>Date ".$nameoftour->date;
Then I need to add these dates into a javascript var to use in datepicker. Below works perfectly, but I am not able to do with the array $nameoftour->date
<script>
var array = ["2018-10-14","2018-10-15","2018-10-16"];
$('input').datepicker({
beforeShowDay: function(date){
var string = jQuery.datepicker.formatDate('yy-mm-dd', date);
return [ array.indexOf(string) == -1 ]
}
});
(function() {
$.datepicker.setDefaults({
regional: 'en',
buttonImage: "/images/calendar_blue.png",
buttonImageOnly: true,
firstDay: 1,
})
})();
</script>
Updated: This prints out 4 dates:
echo "<br>Date ".$nameoftour->date;
However if I do this trying to save as javascript array it works but I only get the last date of the four dates.
var array=["<?php echo ($nameoftour->date);?>",];
Updated: I got it working:
$xml = new SimpleXMLElement($viajes);
$tmpArrayFechas = [];
foreach ($xml->excursion as $excursion) {
if ($excursion->idmodelo == $cifraexcursion) {
$tmpArrayFechas[] = $excursion->fecha;
}
}
$tmpArrayFechas = implode(',', $tmpArrayFechas);
?>
<input type="hidden" id="plazasDisponibles"
name="plazasDisponibles"
value="<?php echo $tmpArrayFechas; ?>">
<script>
var arrayDiasDisponibles =
document.querySelector("#plazasDisponibles").value.split(',');
$('input').datepicker({
beforeShowDay: function(date){
var string = jQuery.datepicker.formatDate('yy-mm-dd', date);
return [ arrayDiasDisponibles.indexOf(string) !== -1 ]
}
});
(function() {
$.datepicker.setDefaults({
regional: 'en',
buttonImage: "/images/calendar_blue.png",
buttonImageOnly: true,
firstDay: 1,
})
})();
</script>