本文整理汇总了PHP中Parser::xml方法的典型用法代码示例。如果您正苦于以下问题:PHP Parser::xml方法的具体用法?PHP Parser::xml怎么用?PHP Parser::xml使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Parser
的用法示例。
在下文中一共展示了Parser::xml方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: foreach
foreach ($project->fileList as &$fileObject) {
$file = $dom->createElement('file');
$files->appendChild($file);
$path = $dom->createElement('path', $fileObject->path);
$file->appendChild($path);
$size = $dom->createElement('size', $fileObject->size);
$file->appendChild($size);
}
}
echo $dom->saveXML();
}
}
//enable debugging
ini_set('display_errors', true);
ini_set('error_reporting', E_ALL);
//get list data
$list_fp = fopen("http://barril1.projects.cs.illinois.edu/svn_list.xml", "r") or die("Error reading XML data.");
$raw_list_data = "";
while ($data = fread($list_fp, 4096)) {
$raw_list_data = $raw_list_data . $data;
}
// parse data into project data structure
$xml_parser = new Parser();
$parser = $xml_parser->xml();
$projects = $xml_parser->parse($raw_list_data);
// output XML file representing data structure
$output_engine = new OutputEngine();
$output_engine->outputXML($projects);
// free parser memory; close list file
xml_parser_free($parser);
fclose($list_fp);
示例2: test
public function test()
{
$request = ['url' => 'http://thegamesdb.net/api/GetGame.php', 'params' => ['name' => 'harry potter']];
$response = \HttpClient::get($request);
dd(\Parser::xml($response->content()));
}
示例3: newGame
public function newGame(Request $request)
{
// Gets the game data from thegamesdb.net
$data['games'] = [];
if ($request->input('name')) {
if ($request->input('platform')) {
if ($request->input('exact')) {
$req = ['url' => 'http://thegamesdb.net/api/GetGame.php', 'params' => ['exactname' => $request->input('name'), 'platform' => $request->input('platform')]];
} else {
$req = ['url' => 'http://thegamesdb.net/api/GetGame.php', 'params' => ['name' => $request->input('name'), 'platform' => $request->input('platform')]];
}
} else {
if ($request->input('exact')) {
$req = ['url' => 'http://thegamesdb.net/api/GetGame.php', 'params' => ['exactname' => $request->input('name')]];
} else {
$req = ['url' => 'http://thegamesdb.net/api/GetGame.php', 'params' => ['name' => $request->input('name')]];
}
}
$response = \HttpClient::get($req);
// Checks if only 1 game is produced
if (isset(\Parser::xml($response->content())['Game'])) {
$data['games'] = \Parser::xml($response->content())['Game'];
} else {
$data['games'] = [];
}
// Checks if the game returned is only 1
if (isset($data['games']['id'])) {
$valid_platforms = ["Sony Playstation 3", "Sony Playstation 4", "Sony Playstation Vita", "Nintendo 3DS", "PC", "Nintendo Wii U", "Nintendo Wii", "Microsoft Xbox 360", "Microsoft Xbox One"];
$single_game = [];
$single_game[0] = $data['games'];
if (in_array($data['games']['Platform'], $valid_platforms)) {
$data['games'] = $single_game;
} else {
$data['games'] = [];
}
} else {
// FILTER ONLY VALID PLATFORMS
$data['games'] = array_filter($data['games'], function ($var) {
$valid_platforms = ["Sony Playstation 3", "Sony Playstation 4", "Sony Playstation Vita", "Nintendo 3DS", "PC", "Nintendo Wii U", "Nintendo Wii", "Microsoft Xbox 360", "Microsoft Xbox One"];
return in_array($var['Platform'], $valid_platforms);
});
// SORT BY RELEASE DATE
usort($data['games'], function ($a, $b) {
if (array_key_exists('ReleaseDate', $a) && array_key_exists('ReleaseDate', $b)) {
$format = "m/d/Y";
$date1 = \DateTime::createFromFormat($format, $b['ReleaseDate']);
$date2 = \DateTime::createFromFormat($format, $a['ReleaseDate']);
return $date1 > $date2;
}
return false;
});
}
}
$data['valid_platforms'] = ["Sony Playstation 3", "Sony Playstation 4", "Sony Playstation Vita", "Nintendo 3DS", "PC", "Nintendo Wii U", "Nintendo Wii", "Microsoft Xbox 360", "Microsoft Xbox One"];
$perPage = 12;
$currentPage = $request->input('page', 1) - 1;
$pagedData = array_slice($data['games'], $currentPage * $perPage, $perPage);
$page = $request->has('page') ? $request->get('page') : 1;
$data['games'] = new LengthAwarePaginator($pagedData, count($data['games']), $perPage, $page, ['path' => $request->url(), 'query' => $request->query()]);
$data['game_name'] = $request->input('name');
return view('games.new', $data);
}