我一直在与此php代码,这应该会修改谷歌日历布局。但是当我把代码放到页面上时,下面的所有东西都会消失。它有什么问题?
<?php
$your_google_calendar=" PAGE ";
$url= parse_url($your_google_calendar);
$google_domain = $url['scheme'].'://'.$url['host'].dirname($url['path']).'/';
// Load and parse Google's raw calendar
$dom = new DOMDocument;
$dom->loadHTMLfile($your_google_calendar);
// Change Google's CSS file to use absolute URLs (assumes there's only one element)
$css = $dom->getElementByTagName('link')->item(0);
$css_href = $css->getAttributes('href');
$css->setAttributes('href', $google_domain . $css_href);
// Change Google's JS file to use absolute URLs
$scripts = $dom->getElementByTagName('script')->item(0);
foreach ($scripts as $script) {
$js_src = $script->getAttributes('src');
if ($js_src) { $script->setAttributes('src', $google_domain . $js_src); }
}
// Create a link to a new CSS file called custom_calendar.css
$element = $dom->createElement('link');
$element->setAttribute('type', 'text/css');
$element->setAttribute('rel', 'stylesheet');
$element->setAttribute('href', 'custom_calendar.css');
// Append this link at the end of the element
$head = $dom->getElementByTagName('head')->item(0);
$head->appendChild($element);
// Export the HTML
echo $dom->saveHTML();
?>发布于 2013-11-29 01:35:37
当我测试你的代码时,我得到了一些错误,因为错误的方法调用:
->getElementByTagName应为->getElementsByTagName,元素上应为%s
和
->setAttributes和->getAttributes应该是末尾没有%s的->setAttribute和->getAttribute。
我猜你没有打开任何error_reporting,因此不知道出了什么问题?
https://stackoverflow.com/questions/20269369
复制相似问题