- dirname: documentation ( source)
- parse_url: documentation ( source)
<?php
$your_google_calendar="https://www.google.com/calendar/embed?showTitle=0&showPrint=0&showTabs=0&showCalendars=0&height=800&wkst=1&hl=pt_BR&bgcolor=%23FFFFFF&src=tprotegetreinamentos%40gmail.com&color=%23BE6D00&ctz=America%2FSao_Paulo";
$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->getElementsByTagName('link')->item(0);
$css = $dom->getElementsByTagName('link');
foreach ($css as $link) {
$css_href = $link->getAttribute('href');
if ($css_href) $$link->setAttribute('href', $google_domain . $css_href);
}
//$css_href = $css->getAttribute('href');
//$css->setAttribute('href', $google_domain . $css_href);
// Change Google's JS file to use absolute URLs
$scripts = $dom->getElementsByTagName('script');
foreach ($scripts as $script) {
$js_src = $script->getAttribute('src');
if ($js_src) $script->setAttribute('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
//DOMNodeList
$head = $dom->getElementsByTagName('head');
//
$head = $dom->getElementsByTagName('head')->item(0);
echo($head);
$head->appendChild($element);
// Export the HTML
//echo $dom->saveHTML();
?>