FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
processing-docs/generate/domit/xml_domit_doctor.php at macos · processing/processing-docs · GitHub
processing
processing-docs
Repository navigation
Code
Issues
3
(3)
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
processing-docs
/
generate
/
domit
/
xml_domit_doctor.php
Copy path
More file actions
More file actions
Latest commit
History
History
History
94 lines (85 loc) · 2.23 KB
Breadcrumbs
processing-docs
/
generate
/
domit
/
xml_domit_doctor.php
Copy path
File metadata and controls
94 lines (85 loc) · 2.23 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
/**
* DOMIT! Doctor is a set of utilities for repairing malformed XML
* @package domit-xmlparser
* @copyright (C) 2004 John Heinstein. All rights reserved
* @license http://www.gnu.org/copyleft/lesser.html LGPL License
* @author John Heinstein <johnkarl@nbnet.nb.ca>
* @link http://www.engageinteractive.com/domit/ DOMIT! Home Page
* DOMIT! is Free Software
**/
/**
* A (static) class containing utilities for repairing malformed XML
*
* @package domit-xmlparser
* @author John Heinstein <johnkarl@nbnet.nb.ca>
*/
class
domit_doctor {
/**
* Looks for illegal ampersands and converts them to entities
* @param string The xml text to be repaired
* @return string The repaired xml text
*/
function
fixAmpersands
(
$
xmlText
) {
$
xmlText
=
trim
(
$
xmlText
);
$
startIndex
= -
1
;
$
processing
=
true
;
$
illegalChar
=
'
&
'
;
while
(
$
processing
) {
$
startIndex
=
strpos
(
$
xmlText
,
$
illegalChar
, (
$
startIndex
+
1
));
if
(
$
startIndex
!==
false
) {
$
xmlText
= domit_doctor::
evaluateCharacter
(
$
xmlText
,
$
illegalChar
, (
$
startIndex
+
1
));
}
else
{
$
processing
=
false
;
}
}
return
$
xmlText
;
}
//fixAmpersands
/**
* Evaluates whether an ampersand should be converted to an entity, and performs the conversion
* @param string The xml text
* @param string The (ampersand) character
* @param int The character index immediately following the ampersand in question
* @return string The repaired xml text
*/
function
evaluateCharacter
(
$
xmlText
,
$
illegalChar
,
$
startIndex
) {
$
total
=
strlen
(
$
xmlText
);
$
searchingForCDATASection
=
false
;
for
(
$
i
=
$
startIndex
;
$
i
<
$
total
;
$
i
++) {
$
currChar
=
substr
(
$
xmlText
,
$
i
,
1
);
if
(!
$
searchingForCDATASection
) {
switch
(
$
currChar
) {
case
'
'
:
case
"
'
"
:
case
'
"
'
:
case
"\n"
:
case
"\r"
:
case
"\t"
:
case
'
&
'
:
case
"
]
"
:
$
searchingForCDATASection
=
true
;
break
;
case
"
;
"
:
return
$
xmlText
;
break
;
}
}
else
{
switch
(
$
currChar
) {
case
'
<
'
:
case
'
>
'
:
return
(
substr_replace
(
$
xmlText
,
'
&
'
,
(
$
startIndex
-
1
) ,
1
));
break
;
case
"
]
"
:
return
$
xmlText
;
break
;
}
}
}
return
$
xmlText
;
}
//evaluateCharacter
}
//domit_doctor
?>
Back
|
FazBrowse Home
|
New Git URL