-
Notifications
You must be signed in to change notification settings - Fork 0
/
Data.php
55 lines (55 loc) · 1.74 KB
/
Data.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
require_once('ML.class.php');
$ML = new ML();
if(isset($_POST['FormData'])){
$search = trim($_POST['FormData']);
libxml_use_internal_errors(true);
$Full_URL = "http://www.tripadvisor.com" . $ML -> getHalf_URL($search);
echo $Response = $ML -> getData($Full_URL);
}
else if(isset($_POST['LiveData'])){
//Get Post data
$_Interests = $_POST['LiveData'];
session_start();
//Write to file
$_FileName = 'store/'.$_SESSION['users'].'.txt';
file_put_contents($_FileName,$_Interests);
}
else if(isset($_POST['Targets']) && isset($_POST['startDate'])){
//Get Post data
$Targets = json_decode($_POST['Targets']);
$startDate = $_POST['startDate'];
session_start();
//Write to file
$_FileName = 'store/'.$_SESSION['users'].'-Schedule.xml';
//file_put_contents($_FileName,$Targets);
//creating object of SimpleXMLElement
$xml_user_info = new SimpleXMLElement("<?xml version=\"1.0\"?><Date></Date>");
$xml_user_info -> addAttribute('Start', $startDate);
//function call to convert array to xml
array_to_xml($Targets, $xml_user_info);
//saving generated xml file
$xml_file = $xml_user_info->asXML($_FileName);
}
else{
echo 'Empty Request';
}
/////////////////////////////////////////////////////////////
function array_to_xml($array, &$xml_user_info) {
foreach($array as $key => $value) {
if(is_array($value)) {
if(!is_numeric($key)){
$subnode = $xml_user_info->addChild("$key");
array_to_xml($value, $subnode);
}else{
//$key += 1;
$subnode = $xml_user_info->addChild("Day");
array_to_xml($value, $subnode);
}
}else {
//$key += 1;
$xml_user_info->addChild("Place", htmlspecialchars("$value"));
}
}
}
?>