Mercurial > SimpleWebPresenter
annotate common-functions.inc @ 4:74196528fc64
Refac to use xml as input, and remove filters and helper-functions from
main script.
| author | Tom Fredrik "BFG" Klaussen <bfg@blenning.no> |
|---|---|
| date | Thu, 19 May 2011 18:04:33 +0200 |
| parents | |
| children | 18aafb1a8986 |
| rev | line source |
|---|---|
|
4
74196528fc64
Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
1 <?php |
|
74196528fc64
Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
2 function loadFile($sFilename, $sCharset = 'UTF-8') |
|
74196528fc64
Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
3 { |
|
74196528fc64
Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
4 if (floatval(phpversion()) >= 4.3) { |
|
74196528fc64
Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
5 if (!file_exists($sFilename)) return -3; |
|
74196528fc64
Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
6 $sData = file_get_contents($sFilename); |
|
74196528fc64
Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
7 } else { |
|
74196528fc64
Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
8 if (!file_exists($sFilename)) return -3; |
|
74196528fc64
Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
9 $rHandle = fopen($sFilename, 'r'); |
|
74196528fc64
Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
10 if (!$rHandle) return -2; |
|
74196528fc64
Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
11 |
|
74196528fc64
Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
12 $sData = ''; |
|
74196528fc64
Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
13 while(!feof($rHandle)) |
|
74196528fc64
Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
14 $sData .= fread($rHandle, filesize($sFilename)); |
|
74196528fc64
Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
15 fclose($rHandle); |
|
74196528fc64
Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
16 } |
|
74196528fc64
Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
17 if ($sEncoding = mb_detect_encoding($sData, 'auto', true) != $sCharset) { |
|
74196528fc64
Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
18 if ($sEncoding != 1) { |
|
74196528fc64
Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
19 $sData = mb_convert_encoding($sData, $sCharset, $sEncoding); |
|
74196528fc64
Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
20 } |
|
74196528fc64
Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
21 } |
|
74196528fc64
Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
22 return $sData; |
|
74196528fc64
Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
23 } |
|
74196528fc64
Refac to use xml as input, and remove filters and helper-functions from
Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
parents:
diff
changeset
|
24 ?> |
