本文整理汇总了PHP中simplexml_load_file函数的典型用法代码示例。如果您正苦于以下问题:PHP simplexml_load_file函数的具体用法?PHP simplexml_load_file怎么用?PHP simplexml_load_file使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了simplexml_load_file函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getEventbriteEvents
function getEventbriteEvents($eb_keywords, $eb_city, $eb_proximity)
{
global $eb_app_key;
$xml_url = "https://www.eventbrite.com/xml/event_search?...&within=50&within_unit=M&keywords=" . $eb_keywords . "&city=" . $eb_city . "&date=This+month&app_key=" . $eb_app_key;
echo $xml_url . "<br />";
$xml = simplexml_load_file($xml_url);
$count = 0;
// loop over events from eventbrite xml
foreach ($xml->event as $event) {
// add event if it doesn't already exist
$event_query = mysql_query("SELECT * FROM events WHERE id_eventbrite={$event->id}") or die(mysql_error());
if (mysql_num_rows($event_query) == 0) {
echo $event_id . " ";
// get event url
foreach ($event->organizer as $organizer) {
$event_organizer_url = $organizer->url;
}
// get event address
foreach ($event->venue as $venue) {
$event_venue_address = $venue->address;
$event_venue_city = $venue->city;
$event_venue_postal_code = $venue->postal_code;
}
// get event title
$event_title = str_replace(array("\r\n", "\r", "\n"), ' ', $event->title);
// add event to database
mysql_query("INSERT INTO events (id_eventbrite, \n title,\n created, \n organizer_name, \n uri, \n start_date, \n end_date, \n address\n ) VALUES (\n '{$event->id}',\n '" . parseInput($event_title) . "',\n '" . strtotime($event->created) . "',\n '" . trim(parseInput($event->organizer->name)) . "',\n '{$event_organizer_url}',\n '" . strtotime($event->start_date) . "',\n '" . strtotime($event->end_date) . "',\n '{$event_venue_address}, {$event_venue_city}, {$event_venue_postal_code}'\n )") or die(mysql_error());
}
$count++;
}
}
示例2: addConfig
/**
* Add an xml file to the bean definition
* @param $xml
* @param $relatifPath
* @return unknown_type
*/
public function addConfig($xmlFile)
{
$xmlFile = $this->getFullPath($xmlFile);
$xml = @simplexml_load_file($xmlFile);
if ($xml == false) {
$str = "Error parsing file (" . libxml_get_last_error()->file . ") on line (" . libxml_get_last_error()->line . ") : " . libxml_get_last_error()->message;
echo $str;
throw new \org\equinox\exception\EquinoxException($str);
}
$currentContextPath = dirname($xmlFile);
foreach ($xml->{'component-scan'} as $scan) {
$this->getComponentScan()->scanPackage((string) $scan['base-package']);
}
foreach ($xml->{'ini-file'} as $iniFile) {
$this->addIniFile($currentContextPath, $iniFile);
}
foreach ($xml->bean as $bean) {
$this->addBean($bean, $xmlFile);
}
foreach ($xml->import as $import) {
$resource = $currentContextPath . '/' . (string) $import['resource'];
$this->addConfig($resource);
}
foreach ($xml->modules as $module) {
$this->loadModules($this->applicationContext->getIniValue((string) $module->iniValue));
}
}
示例3: address_to_xml
/**
* Retrieves the XML geocode address lookup.
* ! Results of this method are cached for 1 day.
*
* @param string $address adress
* @return object SimpleXML
*/
public static function address_to_xml($address)
{
static $cache;
// Load Cache
if ($cache === NULL) {
$cache = Cache::instance();
}
// Address cache key
$key = 'gmap-address-' . sha1($address);
if ($xml = $cache->get($key)) {
// Return the cached XML
return simplexml_load_string($xml);
} else {
// Set the XML URL
$xml = Gmap::api_url('maps/geo', array('output' => 'xml', 'q' => $address), '&');
// Disable error reporting while fetching the feed
$ER = error_reporting(~E_NOTICE);
// Load the XML
$xml = simplexml_load_file($xml);
if (is_object($xml) and $xml instanceof SimpleXMLElement and (int) $xml->Response->Status->code === 200) {
// Cache the XML
$cache->set($key, $xml->asXML(), array('gmaps'), 86400);
} else {
// Invalid XML response
$xml = FALSE;
}
// Turn error reporting back on
error_reporting($ER);
}
return $xml;
}
示例4: load
/**
* Returns array of simple xml objects, where key is a handle name
*
* @return SimpleXmlElement[]
* @throws RuntimeException in case of load error (malformed xml, etc)
*/
public function load()
{
$this->validate();
$original = libxml_use_internal_errors(true);
$simpleXmlElement = simplexml_load_file($this->filePath);
$errors = libxml_get_errors();
libxml_clear_errors();
libxml_use_internal_errors($original);
if ($simpleXmlElement === false) {
$messages = array();
foreach ($errors as $error) {
$messages[] = sprintf('%s, line %s, column %s', trim($error->message), $error->line, $error->column);
}
throw new RuntimeException(sprintf('File "%s" has a malformed xml structure: %s', $this->filePath, PHP_EOL . implode(PHP_EOL, $messages)));
}
$stringXml = array();
// First convert all elements to string,
// as in xml file can be multiple string with the same handle names
foreach ($simpleXmlElement->children() as $key => $element) {
if (!isset($stringXml[$key])) {
$stringXml[$key] = '';
}
foreach ($element->children() as $child) {
$stringXml[$key] .= $child->asXml();
}
}
$result = array();
foreach ($stringXml as $key => $xml) {
$result[$key] = simplexml_load_string(sprintf('<%1$s>%2$s</%1$s>', $key, $xml));
}
return $result;
}
示例5: ApplyChanges
public function ApplyChanges()
{
parent::ApplyChanges();
$this->RegisterAction('Volume', 'Lautstärke', $typ = 1, $profil = '');
$this->RegisterAction('Mute', 'Stumm', $typ = 0, $profil = 'RPC.OnOff');
$this->RegisterVariableInteger('GroupMember', 'Gruppe', 0);
if ($this->CheckConfig() === true) {
$zoneConfig = IPS_GetKernelDir() . '/modules/ips2rpc/sonos_zone.config';
if (!file_exists($zoneConfig)) {
$file = $this->API()->BaseUrl(true) . '/status/topology';
if ($xml = simplexml_load_file($file)) {
$out = [];
foreach ($xml->ZonePlayers->ZonePlayer as $item) {
if ($v = (array) $item->attributes()) {
$v = array_shift($v);
}
$v['name'] = (string) $item;
$out[$v['name']] = $v;
}
file_put_contents($zoneConfig, serialize($out));
}
}
$this->Update();
}
}
示例6: getCommands
/**
* Get the list of commands
*
* Will attempt to use information from the xml manifest if possible
*
* @return array
*/
public function getCommands()
{
$name = $this->getController()->getIdentifier()->name;
$package = $this->_identifier->package;
$manifest = JPATH_ADMINISTRATOR.'/components/com_'.$package.'/manifest.xml';
if(file_exists($manifest))
{
$xml = simplexml_load_file($manifest);
if(isset($xml->administration->submenu))
{
foreach($xml->administration->submenu->children() as $menu)
{
$view = (string)$menu['view'];
$this->addCommand(JText::_((string)$menu), array(
'href' => JRoute::_('index.php?option=com_'.$package.'&view='.$view),
'active' => ($name == KInflector::singularize($view))
));
}
}
}
return parent::getCommands();
}
示例7: pestle_cli
/**
* Generates plugin XML
* This command generates the necessary files and configuration
* to "plugin" to a preexisting Magento 2 object manager object.
*
* pestle.phar generate_plugin_xml Pulsestorm_Helloworld 'Magento\Framework\Logger\Monolog' 'Pulsestorm\Helloworld\Plugin\Magento\Framework\Logger\Monolog'
*
* @argument module_name Create in which module? [Pulsestorm_Helloworld]
* @argument class Which class are you plugging into? [Magento\Framework\Logger\Monolog]
* @argument class_plugin What's your plugin class name? [<$module_name$>\Plugin\<$class$>]
* @command generate_plugin_xml
*/
function pestle_cli($argv)
{
// $module_info = askForModuleAndReturnInfo($argv);
$module_info = getModuleInformation($argv['module_name']);
$class = $argv['class'];
$class_plugin = $argv['class_plugin'];
$path_di = $module_info->folder . '/etc/di.xml';
if (!file_exists($path_di)) {
$xml = simplexml_load_string(getBlankXml('di'));
writeStringToFile($path_di, $xml->asXml());
output("Created new {$path_di}");
}
$xml = simplexml_load_file($path_di);
// $plugin_name = strToLower($module_info->name) . '_' . underscoreClass($class);
// simpleXmlAddNodesXpath($xml,
// "/type[@name=$class]/plugin[@name=$plugin_name,@type=$class_plugin]");
$type = $xml->addChild('type');
$type->addAttribute('name', $class);
$plugin = $type->addChild('plugin');
$plugin->addAttribute('name', strToLower($module_info->name) . '_' . underscoreClass($class));
$plugin->addAttribute('type', $class_plugin);
writeStringToFile($path_di, formatXmlString($xml->asXml()));
output("Added nodes to {$path_di}");
$path_plugin = getPathFromClass($class_plugin);
$body = implode("\n", [' //function beforeMETHOD($subject, $arg1, $arg2){}', ' //function aroundMETHOD($subject, $procede, $arg1, $arg2){return $proceed($arg1, $arg2);}', ' //function afterMETHOD($subject, $result){return $result;}']);
$class_definition = str_replace('<$body$>', "\n{$body}\n", createClassTemplate($class_plugin));
writeStringToFile($path_plugin, $class_definition);
output("Created file {$path_plugin}");
}
示例8: createMainPage
/**
* Create main page of the site and set rights for it.
*
* @param int $id Site ID.
*/
private function createMainPage($id)
{
//Ищем в перечне шаблонов модуля по которому создан сайт, шаблоны отмеченные аттрибутом default
//если не находим - берем default.[type].xml
//а если и такого нет - берем шаблон default.[type].xml из ядра ..а что делать?
$module = $this->getData()->getFieldByName('site_folder')->getRowData(0);
$content = $layout = false;
foreach (array('content', 'layout') as $type) {
foreach (glob(implode(DIRECTORY_SEPARATOR, array(SITE_DIR, self::MODULES, $module, 'templates', $type, '*'))) as $path) {
if ($xml = simplexml_load_file($path)) {
$attrs = $xml->attributes();
if (isset($attrs['default'])) {
${$type} = $module . '/' . basename($path);
break;
}
}
}
if (!${$type} && file_exists(implode(DIRECTORY_SEPARATOR, array(SITE_DIR, self::MODULES, $module, 'templates', $type, 'default.' . $type . '.xml')))) {
${$type} = $module . '/' . 'default.' . $type . '.xml';
}
if (!${$type}) {
${$type} = 'default.' . $type . '.xml';
}
//Если шаблона там не окажется
//та пошло оно в жопу ...это ж не для ядерного реактора ПО
}
$translationTableName = 'share_sites_translation';
//Если не задан параметр конфигурации - создаем одну страницу
$smapId = $this->dbh->modify(QAL::INSERT, 'share_sitemap', array('smap_content' => $content, 'smap_layout' => $layout, 'site_id' => $id, 'smap_segment' => QAL::EMPTY_STRING));
foreach ($_POST[$translationTableName] as $langID => $siteInfo) {
$this->dbh->modify(QAL::INSERT, 'share_sitemap_translation', array('lang_id' => $langID, 'smap_id' => $smapId, 'smap_name' => $siteInfo['site_name']));
}
//права берем ориентируясь на главную страницу дефолтного сайта
$this->dbh->modify('INSERT IGNORE INTO share_access_level ' . '(smap_id, right_id, group_id) ' . 'SELECT %s, al.right_id, al.group_id ' . 'FROM `share_access_level` al ' . 'LEFT JOIN share_sitemap s ON s.smap_id = al.smap_id ' . 'WHERE s.smap_pid is NULL AND site_id= %s', $smapId, E()->getSiteManager()->getDefaultSite()->id);
}
示例9: __construct
private function __construct($strPath)
{
if (!file_exists($strPath)) {
throw new Exception("Plugin config file does not exist: " . $strPath);
}
$this->mixPluginSet = simplexml_load_file($strPath);
}
示例10: getPlatform
/**
* Checks which edition is used
* @return int
*/
public static function getPlatform()
{
if (self::$_platform == -1) {
$pathToClaim = BP . DS . "app" . DS . "etc" . DS . "modules" . DS . self::ENTERPRISE_DETECT_COMPANY . "_" . self::ENTERPRISE_DETECT_EXTENSION . ".xml";
$pathToEEConfig = BP . DS . "app" . DS . "code" . DS . "core" . DS . self::ENTERPRISE_DETECT_COMPANY . DS . self::ENTERPRISE_DETECT_EXTENSION . DS . "etc" . DS . "config.xml";
$isCommunity = !file_exists($pathToClaim) || !file_exists($pathToEEConfig);
if ($isCommunity) {
self::$_platform = self::CE_PLATFORM;
} else {
$_xml = @simplexml_load_file($pathToEEConfig, 'SimpleXMLElement', LIBXML_NOCDATA);
if (!$_xml === FALSE) {
$package = (string) $_xml->default->design->package->name;
$theme = (string) $_xml->install->design->theme->default;
$skin = (string) $_xml->stores->admin->design->theme->skin;
$isProffessional = $package == self::PROFESSIONAL_DESIGN_NAME && $theme == self::PROFESSIONAL_DESIGN_NAME && $skin == self::PROFESSIONAL_DESIGN_NAME;
if ($isProffessional) {
self::$_platform = self::PE_PLATFORM;
return self::$_platform;
}
}
self::$_platform = self::EE_PLATFORM;
}
}
return self::$_platform;
}
示例11: pestle_cli
/**
* Creates a Route XML
* generate_route module area id
* @command generate_route
*/
function pestle_cli($argv)
{
$module_info = askForModuleAndReturnInfo($argv);
$module = $module_info->name;
$legend = ['frontend' => 'standard', 'adminhtml' => 'admin'];
$areas = array_keys($legend);
$area = inputOrIndex('Which area? [frontend, adminhtml]', 'frontend', $argv, 1);
$router_id = $legend[$area];
if (!in_array($area, $areas)) {
throw new Exception("Invalid areas");
}
$frontname = inputOrIndex('Frontname/Route ID?', null, $argv, 2);
$route_id = $frontname;
$path = $module_info->folder . '/etc/' . $area . '/routes.xml';
if (!file_exists($path)) {
$xml = simplexml_load_string(getBlankXml('routes'));
writeStringToFile($path, $xml->asXml());
}
$xml = simplexml_load_file($path);
simpleXmlAddNodesXpath($xml, "router[@id={$router_id}]/" . "route[@id={$route_id},@frontName={$frontname}]/" . "module[@name={$module}]");
writeStringToFile($path, formatXmlString($xml->asXml()));
$class = str_replace('_', '\\', $module) . '\\Controller\\Index\\Index';
$controllerClass = createControllerClass($class, $area);
$path_controller = getPathFromClass($class);
writeStringToFile($path_controller, $controllerClass);
output($path);
output($path_controller);
}
示例12: import_file
public function import_file($filename, $filetype = "xml", $destdir = "")
{
// test sur validité du paramètre filename et type
if ($filename == "" || $filename == null) {
throw new odException("Class : odImportExport - Method : import_file - Error : give a good filename to import");
}
if (!file_exists($filename)) {
throw new odException("Class : odImportExport - Method : import_file - Error : " . $filename . " does'nt exists");
}
if ($filetype == null || $filetype == "") {
throw new odException("Class : odImportExport - Method : import_file - Error : give a good filename type to import");
}
// cas des fichiers xml
switch ($filetype) {
case "xml":
$xml = simplexml_load_file($filename, null, LIBXML_NOCDATA);
$json = json_encode($xml);
$xml_tree = json_decode($json, TRUE);
if (isset($xml_tree["drops"])) {
$drops = $xml_tree["drops"]["drop_request"];
} else {
$drops = array();
}
if (isset($xml_tree["creates"])) {
$creates = $xml_tree["creates"]["create_request"];
} else {
$creates = array();
}
if (isset($xml_tree["deletes"])) {
$deletes = $xml_tree["deletes"]["delete_request"];
} else {
$deletes = array();
}
if (isset($xml_tree["inserts"])) {
$inserts = $xml_tree["inserts"]["insert_request"];
} else {
$inserts = array();
}
$all_requests = array();
$all_requests = array_merge($all_requests, $drops);
$all_requests = array_merge($all_requests, $deletes);
$all_requests = array_merge($all_requests, $creates);
$all_requests = array_merge($all_requests, $inserts);
// Instanciation de l'outil de fabrication des requêtes
$request = odDatabaseRequest::getInstance();
// Utilisation de la base concernée
$request->makeRequest("USE " . $this->_basename);
$result = $request->runQuery();
foreach ($all_requests as $req) {
$request->makeRequest(str_replace("\n", "", $req));
$request->runQuery();
}
break;
case "zip":
odZip::unZip($filename, $destdir);
break;
default:
throw new odException("Class : odImportExport - Method : import_file - Error : bad type (" . $type . ") for filename : " . $filename);
}
}
示例13: pestle_cli
/**
* Generates Magento 2 Observer
* This command generates the necessary files and configuration to add
* an event observer to a Magento 2 system.
*
* pestle.phar generate_observer Pulsestorm_Generate controller_action_predispatch pulsestorm_generate_listener3 'Pulsestorm\Generate\Model\Observer3'
*
* @command generate_observer
* @argument module Full Module Name? [Pulsestorm_Generate]
* @argument event_name Event Name? [controller_action_predispatch]
* @argument observer_name Observer Name? [<$module$>_listener]
* @argument model_name Class Name? [<$module$>\Model\Observer]
*/
function pestle_cli($argv)
{
$module = $argv['module'];
$event_name = $argv['event_name'];
$observer_name = $argv['observer_name'];
$model_name = $argv['model_name'];
$method_name = 'execute';
$path_xml_event = initilizeModuleConfig($module, 'events.xml', 'urn:magento:framework:Event/etc/events.xsd');
$xml = simplexml_load_file($path_xml_event);
$nodes = $xml->xpath('//event[@name="' . $event_name . '"]');
$node = array_shift($nodes);
$event = $node;
if (!$node) {
$event = $node ? $node : $xml->addChild('event');
$event->addAttribute('name', $event_name);
}
$observer = $event->addChild('observer');
$observer->addAttribute('name', $observer_name);
$observer->addAttribute('instance', $model_name);
// $observer->addAttribute('method', $method_name);
output("Creating: {$path_xml_event}");
$path = writeStringToFile($path_xml_event, $xml->asXml());
output("Creating: {$model_name}");
$contents = createClassTemplate($model_name, false, '\\Magento\\Framework\\Event\\ObserverInterface');
$contents = str_replace('<$body$>', "\n" . ' public function execute(\\Magento\\Framework\\Event\\Observer $observer){exit(__FILE__);}' . "\n", $contents);
createClassFile($model_name, $contents);
}
示例14: index
public function index()
{
$this->data = $this->load->language('extension/payment');
$this->document->setTitle($this->language->get('heading_title'));
$this->data['breadcrumbs'] = array();
$this->data['breadcrumbs'][] = array('text' => $this->language->get('text_home'), 'href' => $this->url->link('common/dashboard', 'token=' . $this->session->data['token'], 'SSL'));
$this->data['breadcrumbs'][] = array('text' => $this->language->get('heading_title'), 'href' => $this->url->link('extension/payment', 'token=' . $this->session->data['token'], 'SSL'));
$this->data['success'] = $this->build->data('success', $this->session->data);
$this->data['error_warning'] = $this->build->data('warning', $this->error);
$this->load->model('extension/extension');
$extensions = $this->model_extension_extension->getInstalled('payment');
foreach ($extensions as $key => $value) {
if (!file_exists(DIR_EXTENSION . 'payment/' . $value . '/controller/' . $value . '.php')) {
$this->model_extension_extension->uninstall('payment', $value);
unset($extensions[$key]);
}
}
$this->data['extensions'] = array();
$files = glob(DIR_EXTENSION . 'payment/*', GLOB_ONLYDIR);
if ($files) {
foreach ($files as $file) {
$extension = basename($file);
$this->load->language('payment/' . $extension . '/' . $extension);
$xml = simplexml_load_file(DIR_EXTENSION . 'payment/' . $extension . '/details.xml');
$this->data['extensions'][] = array('name' => $this->language->get('heading_title'), 'author' => $xml->author, 'url' => $xml->url, 'version' => $xml->version, 'email' => $xml->email, 'code' => $extension, 'status' => $this->config->get($extension . '_status'), 'sort_order' => $this->config->get($extension . '_sort_order'), 'edit' => $this->url->link('payment/' . $extension . '/' . $extension, 'token=' . $this->session->data['token'], 'SSL'), 'install' => $this->url->link('extension/payment/install', 'token=' . $this->session->data['token'] . '&extension=' . $extension, 'SSL'), 'uninstall' => $this->url->link('extension/payment/uninstall', 'token=' . $this->session->data['token'] . '&extension=' . $extension, 'SSL'), 'installed' => in_array($extension, $extensions));
}
}
$this->data['token'] = $this->session->data['token'];
$this->data['header'] = $this->load->controller('common/header');
$this->data['footer'] = $this->load->controller('common/footer');
$this->response->setOutput($this->render('extension/payment.tpl'));
}
示例15: compute
public function compute($XMLfile)
{
$doc = simplexml_load_file($XMLfile);
foreach ($doc->patch_list->patch as $patch) {
$tab = array();
$last = 0;
$i = 0;
foreach ($patch->children() as $op) {
$rang = (int) $op["position"];
if ($op->getName() == "insert") {
$tab[$rang]["insert"][] = $op;
} else {
$tab[$rang]["delete"][] = $op;
}
}
$delta = 0;
$this->clock = utils::getNextClock();
foreach ($tab as $rang => $liste_op) {
$ligne = $rang + 1 + $delta;
$nb_ins = isset($liste_op["insert"]) ? count($liste_op["insert"]) : 0;
$nb_del = isset($liste_op["delete"]) ? count($liste_op["delete"]) : 0;
for ($i = 0; $i < $nb_del; $i++) {
$logoot_op = $this->generate_del_line($ligne, $liste_op["delete"][$i]);
}
if ($nb_ins > 0) {
$logoot_op_list = $this->generate_ins_text($ligne, $liste_op["insert"]);
}
$delta += $nb_ins - $nb_del;
}
}
}