XMLencode.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php // $Id: XMLencode.php 4083 2005-04-06 19:54:16Z yannoo $
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2005 Dokeos S.A.
  6. Copyright (c) 2005 Warnier Yannick
  7. Copyright (c) 2004 Denes Nagy
  8. For a full list of contributors, see "credits.txt".
  9. The full license can be read in "license.txt".
  10. This program is free software; you can redistribute it and/or
  11. modify it under the terms of the GNU General Public License
  12. as published by the Free Software Foundation; either version 2
  13. of the License, or (at your option) any later version.
  14. See the GNU General Public License for more details.
  15. Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
  16. ==============================================================================
  17. */
  18. /**
  19. ==============================================================================
  20. * @package dokeos.scorm
  21. ==============================================================================
  22. */
  23. /**
  24. * Gets the encoding of the XML file given
  25. * @param string File path
  26. * @return string Encoding found
  27. * @author imandak80, main author
  28. * @author Yannick Warnier <ywarnier@beeznest.org>, fixes
  29. * @date unknown, reviewed on 6 April 2005
  30. */
  31. function GetXMLEncode($file)
  32. {
  33. if (!($fp = fopen($file, "r"))) {
  34. echo "could not open XML input : $file";
  35. }
  36. $fline = fgets($fp);
  37. // if some Windows special chars are found, return Windows encoding
  38. fseek($fp,0);
  39. $thefile=fread($fp,filesize($file));
  40. if (strpos($thefile,'&#233;') or strpos($thefile,'&#235;')) { return('windows-1252'); }
  41. // else get the string located between double quotes after string "ing=" (for "encoding")
  42. $match = array(); //initialize result var
  43. preg_match('/encoding="([0-9a-zA-Z-]*)"/i',$fline,$match); //find quoted encoding
  44. return $match[1]; // return with encoding type
  45. }
  46. ?>