PHP7 xml_parse()更改,截断数组?

时间:2017-09-30 17:43:47

标签: xml-parsing php-5.6 php-7.1 ims

我在xml_parse()函数中出现的问题 ATutor QTI Parser

我希望有人可以指出我错过的内容,或者想出一个解决PHP 7.1.1的方法。

我发现没有文档或帖子在这里建议将PHP xml_parse()函数从5.6更改为7.1,尽管这两个版本似乎以不同方式解析xml。正在解析的XML出现在下面。

具体来说,对于示例中的问题数组,5.6.30返回一系列问题,如:

[question] => Array
    (
        [0] => graphic matching
        [1] => LIKERT
        [2] => multi choice question
        [3] => Mutliple question
        [4] => open ended
        [5] => ordering
        [6] => Simple match
        [7] => true
    )

使用php 7.1.1时,其他所有内容都是相同的,它只返回上面每个数组元素的第一个字母,作为字符串。

[question] => gLmMooSt

XML文件是来自QTI测试(即测验)包的IMS QTI 1.2.1清单。

发生截断的元素是问题标题(问题本身),在以下元素中找到,当使用PHP5.6([0] =>图形匹配)时,它返回数组中的第一个元素,并在使用PHP7.1.1时在问题字符串中返回第一个字母" g"([问题] => gLmMooSt)

<material>
        <mattext texttype="text/html">graphic matching</mattext>
</material>

&#13;
&#13;
<?xml version="1.0" encoding="utf-8"?>

<questestinterop  
  xmlns="http://www.imsglobal.org/xsd/ims_qtiasiv1p2"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xsi:schemaLocation="http://www.imsglobal.org/xsd/ims_qtiasiv1p2 http://www.imsglobal.org/profile/cc/ccv1p0/derived_schema/domainProfile_4/ims_qtiasiv1p2_localised.xsd"
>
	<assessment title="Simple test" ident="d41d8cd98f00b204e9800998ecf8427e">
                
		<section ident="ATUTOR-8" title="Simple test">
		<!-- matching question with partial marks -->
		<item title="Mathcing question" ident="ITEM_2">
			<itemmetadata>
				<qtimetadata>
					<qtimetadatafield>
						<fieldlabel>qmd_itemtype</fieldlabel>
						<fieldentry>Logical Groups</fieldentry>
					</qtimetadatafield>
					<qtimetadatafield>
						<fieldlabel>qmd_questiontype</fieldlabel>
						<fieldentry>Drag-and-drop</fieldentry>
					</qtimetadatafield>
                    <qtimetadatafield>
                        <fieldlabel>cc_profile</fieldlabel>
                        <fieldentry>cc.pattern_match.v0p1</fieldentry>
                    </qtimetadatafield>
                    <qtimetadatafield>
                        <fieldlabel>cc_weighting</fieldlabel>
                        <fieldentry>5</fieldentry>
                    </qtimetadatafield>
				</qtimetadata>
			</itemmetadata>
			<presentation>
				<flow>
					<material>
						<mattext texttype="text/html">graphic matching</mattext>
					</material>
							
					<response_lid ident="RESPONSE-98f13708210194c475687be6106a3b84" rcardinality="Multiple">
						<material>
							<mattext texttype="text/html">a</mattext>
						</material>
						<render_choice shuffle="No">
													<response_label ident="Option0">	
								<flow_mat>
									<material>
										<mattext texttype="text/html">A</mattext>
									</material>
								</flow_mat>
							</response_label>
													<response_label ident="Option1">	
								<flow_mat>
									<material>
										<mattext texttype="text/html">B</mattext>
									</material>
								</flow_mat>
							</response_label>
												</render_choice>
					</response_lid>
							
					<response_lid ident="RESPONSE-3c59dc048e8850243be8079a5c74d079" rcardinality="Multiple">
						<material>
							<mattext texttype="text/html">b</mattext>
						</material>
						<render_choice shuffle="No">
													<response_label ident="Option0">	
								<flow_mat>
									<material>
										<mattext texttype="text/html">A</mattext>
									</material>
								</flow_mat>
							</response_label>
													<response_label ident="Option1">	
								<flow_mat>
									<material>
										<mattext texttype="text/html">B</mattext>
									</material>
								</flow_mat>
							</response_label>
												</render_choice>
					</response_lid>
									</flow>
			</presentation>

			<resprocessing>
				<outcomes>
					<decvar varname="SCORE" />
				</outcomes>
																				</resprocessing>
				</item>


<!-- likert question (aka multiple choice with no correct answer) -->
		<item title="Multiple choice question" ident="ITEM_1">
			<itemmetadata>
				<qtimetadata>
					<qtimetadatafield>
						<fieldlabel>qmd_itemtype</fieldlabel>
						<fieldentry>Logical Identifier</fieldentry>
					</qtimetadatafield>
					<qtimetadatafield>
						<fieldlabel>qmd_questiontype</fieldlabel>
						<fieldentry>Multiple-choice</fieldentry>
					</qtimetadatafield>
                    <qtimetadatafield>
                        <fieldlabel>cc_profile</fieldlabel>
                        <fieldentry>cc.mutliple_choice.v0p1</fieldentry>
                    </qtimetadatafield>
				</qtimetadata>
			</itemmetadata>
			<presentation>
				<flow>
					<material>
						<mattext texttype="text/html">LIKERT</mattext>
					</material>
					<response_lid ident="RESPONSE1" rcardinality="Single">
						<render_choice shuffle="No" minnumber="1" maxnumber="1">
							<flow_label>
															<response_label ident="Choice0">	
									<material>
										<mattext texttype="text/html">A LITTLE</mattext>
									</material>
								</response_label>
															<response_label ident="Choice1">	
									<material>
										<mattext texttype="text/html">A lot</mattext>
									</material>
								</response_label>
														</flow_label>
						</render_choice>
					</response_lid>
				</flow>
			</presentation>

			<resprocessing>
								<respcondition title="CorrectResponse">
					<conditionvar>					
						<varequal respident="RESPONSE1">Choice0</varequal>
					</conditionvar>
					<setvar varname="que_score" action="Set">0</setvar>
				</respcondition>
								<respcondition title="CorrectResponse">
					<conditionvar>					
						<varequal respident="RESPONSE1">Choice1</varequal>
					</conditionvar>
					<setvar varname="que_score" action="Set">0</setvar>
				</respcondition>
							</resprocessing>
		</item>


<!-- single answer multiple choice question -->
		<item title="Multiple choice question" ident="ITEM_5">
			<itemmetadata>
				<qtimetadata>
					<qtimetadatafield>
						<fieldlabel>qmd_itemtype</fieldlabel>
						<fieldentry>Logical Identifier</fieldentry>
					</qtimetadatafield>
					<qtimetadatafield>
						<fieldlabel>qmd_questiontype</fieldlabel>
						<fieldentry>Multiple-choice</fieldentry>
					</qtimetadatafield>
                    <qtimetadatafield>
                        <fieldlabel>cc_profile</fieldlabel>
                        <fieldentry>cc.mutliple_choice.v0p1</fieldentry>
                    </qtimetadatafield>
                    <qtimetadatafield>
                        <fieldlabel>cc_weighting</fieldlabel>
                        <fieldentry>5</fieldentry>
                    </qtimetadatafield>
				</qtimetadata>
			</itemmetadata>
			<presentation>
				<flow>
					<material>
						<mattext texttype="text/html">multi choice question</mattext>
					</material>
					<response_lid ident="RESPONSE5" rcardinality="Single">
						<render_choice shuffle="No" minnumber="1" maxnumber="1">
													<response_label ident="Choice0">
								<flow_mat>
									<material>
										<mattext texttype="text/html">this is correct</mattext>
									</material>
								</flow_mat>
							</response_label>
													<response_label ident="Choice1">
								<flow_mat>
									<material>
										<mattext texttype="text/html">this is wrong</mattext>
									</material>
								</flow_mat>
							</response_label>
													<response_label ident="Choice2">
								<flow_mat>
									<material>
										<mattext texttype="text/html">this is wrong</mattext>
									</material>
								</flow_mat>
							</response_label>
												</render_choice>
					</response_lid>
				</flow>
			</presentation>
			<resprocessing>
				<outcomes>
					<decvar varname="SCORE" />
				</outcomes>
													<respcondition title="CorrectResponse">
					<conditionvar>						
						<varequal respident="RESPONSE5">Choice0</varequal>
					</conditionvar>
					<setvar varname="que_score" action="Set">5</setvar>
				</respcondition>
																																	
			</resprocessing>
				</item>

<!-- multi answer multiple choice question with partial marks -->
		<item title="Multiple answer question" ident="ITEM_4">
			<itemmetadata>
				<qtimetadata>
					<qtimetadatafield>
						<fieldlabel>qmd_itemtype</fieldlabel>
						<fieldentry>Logical Identifier</fieldentry>
					</qtimetadatafield>
	                <qtimetadatafield>
                        <fieldlabel>qmd_questiontype</fieldlabel>
                        <fieldentry>Multiple-response</fieldentry>
                    </qtimetadatafield>
                    <qtimetadatafield>
                        <fieldlabel>cc_profile</fieldlabel>
                        <fieldentry>cc.mutliple_response.v0p1</fieldentry>
                    </qtimetadatafield>
                    <qtimetadatafield>
                        <fieldlabel>cc_weighting</fieldlabel>
                        <fieldentry>5</fieldentry>
                    </qtimetadatafield>
				</qtimetadata>
			</itemmetadata>
			<presentation>
				<flow>
					<material>
						<mattext texttype="text/html">Mutliple question</mattext>
					</material>
					<response_lid ident="RESPONSE4" rcardinality="Multiple">
						<render_choice shuffle="No">
													<response_label ident="Choice0">
								<flow_mat>
									<material>
										<mattext texttype="text/html">coorect</mattext>
									</material>
								</flow_mat>
							</response_label>
														<response_label ident="Choice1">
								<flow_mat>
									<material>
										<mattext texttype="text/html">coorect</mattext>
									</material>
								</flow_mat>
							</response_label>
														<response_label ident="Choice2">
								<flow_mat>
									<material>
										<mattext texttype="text/html">icorrect</mattext>
									</material>
								</flow_mat>
							</response_label>
														<response_label ident="Choice3">
								<flow_mat>
									<material>
										<mattext texttype="text/html">icorrect</mattext>
									</material>
								</flow_mat>
							</response_label>
													</render_choice>
					</response_lid>
				</flow>
			</presentation>
			<resprocessing>
				<outcomes>
					<decvar varname="SCORE" />
				</outcomes>
											<respcondition title="CorrectResponse">
					<conditionvar>						
						<varequal respident="RESPONSE4">Choice0</varequal>
					</conditionvar>
					<setvar varname="Respondus_Correct">5</setvar>
				</respcondition>
															<respcondition title="CorrectResponse">
					<conditionvar>						
						<varequal respident="RESPONSE4">Choice1</varequal>
					</conditionvar>
					<setvar varname="Respondus_Correct">5</setvar>
				</respcondition>
																								</resprocessing>
				</item>


<!-- open ended (free text) question -->
		<item title="Open ended question" ident="ITEM_6">
			<itemmetadata>
				<qtimetadata>
					<qtimetadatafield>
						<fieldlabel>qmd_itemtype</fieldlabel>
						<fieldentry>String</fieldentry>
					</qtimetadatafield>
					<qtimetadatafield>
						<fieldlabel>qmd_questiontype</fieldlabel>
						<fieldentry>FIB-string</fieldentry>
					</qtimetadatafield>
                    <qtimetadatafield>
                        <fieldlabel>cc_profile</fieldlabel>
                        <fieldentry>cc.fib.v0p1</fieldentry>
                    </qtimetadatafield>
                    <qtimetadatafield>
                        <fieldlabel>cc_weighting</fieldlabel>
                        <fieldentry>5</fieldentry>
                    </qtimetadatafield>
				</qtimetadata>
			</itemmetadata>
			<presentation>
				<flow>
					<material>
						<mattext texttype="text/html">open ended</mattext>
					</material>
					<response_str ident="RESPONSE6" rcardinality="Single">
												<render_fib rows="1" columns="5">
							<response_label ident="Choice" />
						</render_fib>
					</response_str>
				</flow>
			</presentation>
				</item>


<!-- ordering question -->
		<item title="Ordering question" ident="ITEM_7">
			<itemmetadata>
				<qtimetadata>
					<qtimetadatafield>
						<fieldlabel>qmd_itemtype</fieldlabel>
						<fieldentry>Logical Identifier</fieldentry>
					</qtimetadatafield>
				</qtimetadata>
			</itemmetadata>
			<presentation>
				<flow>
					<material>
						<mattext texttype="text/html">ordering</mattext>
					</material>
					<response_lid ident="RESPONSE7" rcardinality="Ordered">
						<render_choice shuffle="Yes" minnumber="4" maxnumber="4">
														<response_label ident="Choice0">	
								<flow_mat>
									<material>
										<mattext texttype="text/html">item1</mattext>
									</material>
								</flow_mat>
							</response_label>
														<response_label ident="Choice1">	
								<flow_mat>
									<material>
										<mattext texttype="text/html">itms2</mattext>
									</material>
								</flow_mat>
							</response_label>
														<response_label ident="Choice2">	
								<flow_mat>
									<material>
										<mattext texttype="text/html">item 3</mattext>
									</material>
								</flow_mat>
							</response_label>
														<response_label ident="Choice3">	
								<flow_mat>
									<material>
										<mattext texttype="text/html">items 4</mattext>
									</material>
								</flow_mat>
							</response_label>
													</render_choice>
					</response_lid>
				</flow>
			</presentation>
			<resprocessing>
				<outcomes>
					<decvar varname="SCORE" />
				</outcomes>
								<respcondition title="CorrectResponse">
					<conditionvar>					
						<varequal respident="RESPONSE7">Choice0</varequal>
					</conditionvar>
					<setvar varname="Respondus_Correct">1.25</setvar>
				</respcondition>
								<respcondition title="CorrectResponse">
					<conditionvar>					
						<varequal respident="RESPONSE7">Choice1</varequal>
					</conditionvar>
					<setvar varname="Respondus_Correct">1.25</setvar>
				</respcondition>
								<respcondition title="CorrectResponse">
					<conditionvar>					
						<varequal respident="RESPONSE7">Choice2</varequal>
					</conditionvar>
					<setvar varname="Respondus_Correct">1.25</setvar>
				</respcondition>
								<respcondition title="CorrectResponse">
					<conditionvar>					
						<varequal respident="RESPONSE7">Choice3</varequal>
					</conditionvar>
					<setvar varname="Respondus_Correct">1.25</setvar>
				</respcondition>
							</resprocessing>
				</item>


<!-- matching question with partial marks -->
		<item title="Mathcing question" ident="ITEM_3">
			<itemmetadata>
				<qtimetadata>
					<qtimetadatafield>
						<fieldlabel>qmd_itemtype</fieldlabel>
						<fieldentry>Logical Groups</fieldentry>
					</qtimetadatafield>
					<qtimetadatafield>
						<fieldlabel>qmd_questiontype</fieldlabel>
						<fieldentry>Drag-and-drop</fieldentry>
					</qtimetadatafield>
                    <qtimetadatafield>
                        <fieldlabel>cc_profile</fieldlabel>
                        <fieldentry>cc.pattern_match.v0p1</fieldentry>
                    </qtimetadatafield>
                    <qtimetadatafield>
                        <fieldlabel>cc_weighting</fieldlabel>
                        <fieldentry>5</fieldentry>
                    </qtimetadatafield>
				</qtimetadata>
			</itemmetadata>
			<presentation>
				<flow>
					<material>
						<mattext texttype="text/html">Simple match</mattext>
					</material>
							
					<response_lid ident="RESPONSE-34173cb38f07f89ddbebc2ac9128303f" rcardinality="Multiple">
						<material>
							<mattext texttype="text/html">A</mattext>
						</material>
						<render_choice shuffle="No">
													<response_label ident="Option0">	
								<flow_mat>
									<material>
										<mattext texttype="text/html">A</mattext>
									</material>
								</flow_mat>
							</response_label>
													<response_label ident="Option1">	
								<flow_mat>
									<material>
										<mattext texttype="text/html">B</mattext>
									</material>
								</flow_mat>
							</response_label>
												</render_choice>
					</response_lid>
							
					<response_lid ident="RESPONSE-c16a5320fa475530d9583c34fd356ef5" rcardinality="Multiple">
						<material>
							<mattext texttype="text/html">B</mattext>
						</material>
						<render_choice shuffle="No">
													<response_label ident="Option0">	
								<flow_mat>
									<material>
										<mattext texttype="text/html">A</mattext>
									</material>
								</flow_mat>
							</response_label>
													<response_label ident="Option1">	
								<flow_mat>
									<material>
										<mattext texttype="text/html">B</mattext>
									</material>
								</flow_mat>
							</response_label>
												</render_choice>
					</response_lid>
									</flow>
			</presentation>

			<resprocessing>
				<outcomes>
					<decvar varname="SCORE" />
				</outcomes>
											<respcondition title="CorrectResponse">
					<conditionvar>						
						<varequal respident="RESPONSE-34173cb38f07f89ddbebc2ac9128303f">Option0</varequal>
					</conditionvar>
					<setvar varname="Respondus_Correct">5</setvar>
				</respcondition>
															<respcondition title="CorrectResponse">
					<conditionvar>						
						<varequal respident="RESPONSE-c16a5320fa475530d9583c34fd356ef5">Option1</varequal>
					</conditionvar>
					<setvar varname="Respondus_Correct">5</setvar>
				</respcondition>
										</resprocessing>
					<itemfeedback ident="FEEDBACK">
				<solution>
					<solutionmaterial>
						<flow_mat>
							<material>
								<mattext texttype="text/html">Optional Feedback</mattext>
							</material>
						</flow_mat>
					</solutionmaterial>
				</solution>
			</itemfeedback>
				</item>


<!-- true or false question (aka multiple choice with two choices) -->
		<item title="True or False question" ident="ITEM_8">
			<itemmetadata>
				<qtimetadata>
					<qtimetadatafield>
						<fieldlabel>qmd_itemtype</fieldlabel>
						<fieldentry>Logical Identifier</fieldentry>
					</qtimetadatafield>
                    <qtimetadatafield>
						<fieldlabel>qmd_questiontype</fieldlabel>
						<fieldentry>True/false</fieldentry>
					</qtimetadatafield>
                    <qtimetadatafield>
						<fieldlabel>cc_profile</fieldlabel>
						<fieldentry>cc.true_false.v0p1</fieldentry>
					</qtimetadatafield>
                    <qtimetadatafield>
						<fieldlabel>cc_weighting</fieldlabel>
						<fieldentry>5</fieldentry>
					</qtimetadatafield>
				</qtimetadata>
			</itemmetadata>
			<presentation>
				<flow>
					<material>
						<mattext texttype="text/html">true</mattext>
					</material>
					<response_lid ident="RESPONSE8" rcardinality="Single">
						<render_choice shuffle="No">
							<response_label ident="ChoiceT">	
								<flow_mat>
									<material>
										<mattext texttype="text/html">True</mattext>
									</material>
								</flow_mat>
							</response_label>
							<response_label ident="ChoiceF">	
								<flow_mat>
									<material>
										<mattext texttype="text/html">False</mattext>
									</material>
								</flow_mat>
							</response_label>
						</render_choice>
					</response_lid>
				</flow>
			</presentation>
			<resprocessing>
				<outcomes>
					<decvar varname="SCORE" />
				</outcomes>
				<respcondition title="CorrectResponse">
					<conditionvar>
						<varequal respident="RESPONSE8">
							ChoiceT						</varequal>
					</conditionvar>
					<setvar varname="que_score" action="Set">5</setvar>
				</respcondition>
			</resprocessing>
				</item>		</section>
	</assessment>
</questestinterop>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:1)

此问题是由此引起的,用于保存数组的变量$question是作为空字符串启动的。

PHP7有一个非常严格的变量类型验证。在PHP7之前,当一个变量在代码中被视为与它启动的类型不同的类型时,PHP会以静默方式将其转换为新类型。使用PHP7,变量在整个代码中被视为初始化类型,在这种情况下,分配给$question的数组值将被截断,以便仅通过从每个数组值中获取第一个字符来组成字符串。