Skip to content

Instantly share code, notes, and snippets.

@mer30hamid
Last active August 29, 2015 14:16
Show Gist options
  • Save mer30hamid/932de85f4f8089058f17 to your computer and use it in GitHub Desktop.
Save mer30hamid/932de85f4f8089058f17 to your computer and use it in GitHub Desktop.
This simple script, corrects moodle iCal utf-8 characters , if you are not Admin and not able to access and correct it on server ! see more here: https://tracker.moodle.org/browse/MDL-30756 how to use: replace $url value to the buggy iCal url, place this file in a self hosting site (your own site) for example: www.yoursite.com/moodle-ical-correc…
<?php
setlocale(LC_ALL, 'fa_IR'); //set your locale https://gist.github.com/jacobbubu/1836273
header('Content-type: text/calendar; charset=utf-8');
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
$url = "http://moodle/buggy/ical/url"; //link to moodles iCal
$badstr = file_get_contents($url);
echo iconv("utf-8", "utf-8//ignore", $badstr);
?>
<?php
//Update: if you can not use file_get_contents()
//or iconv() returns blank string (in new php versions),
//then use this code:
setlocale(LC_ALL, 'fa_IR'); //set your locale https://gist.github.com/jacobbubu/1836273
header('Content-type: text/calendar; charset=utf-8');
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
$url = "http://moodle/buggy/ical/url"; //link to moodles iCal
$ch = curl_init();
curl_setopt_array(
$ch, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true
));
$badstr = curl_exec($ch);
ini_set('mbstring.substitute_character', "none");
echo mb_convert_encoding($badstr, 'UTF-8', 'UTF-8');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment