我正在使用scorm测验,可以将数据作为xml导出到我的服务器。我正在尝试解析该数据,以便我可以使用其中的一些来发送php电子邮件。我现在正在尝试的是返回数字1,我无法弄清楚如何使其工作。帮助
<?php
$version = $_POST['v'];
$points = $_POST['sp'];
$passing_percent = $_POST['psp'];
$gained_score = $_POST['tp'];
$username = $_POST['sn'];
$email = $_POST['se'];
$quiz_title = $_POST['qt'];
$detailed_results_xml = $_POST['dr'];
$xml_string = <<<_XML
print "<?xml version="1.0" encoding="iso-8859-1"?>" . $detailed_results_xml;
_XML;
$xml = simplexml_load_string($xml_string);
$emailtest = print_r($xml);
mail("email@email.com",$quiz_title,$emailtest,"From: fromname <noreply@test.com>");
?>
如果我将$ detailed_results_xml通过电子邮件发给自己,就会发出这样的结论:
<quizReport xmlns="http://www.ispringsolutions.com/ispring/quizbuilder/quizresults" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.ispringsolutions.com/ispring/quizbuilder/quizresults quizReport.xsd" version="1">
<quizSettings quizType="survey" timeLimit="0"/>
<summary time="32">
<variables>
<variable name="USER_NAME" title="Name" value="mike"/>
<variable name="USER_EMAIL" title="Email" value="test.test@test.com"/>
</variables>
</summary>
<questions>
<fillInTheBlankSurveyQuestion id="{BE7284DD-B731-409B-9198-A782499EECA9}" status="answered">
<direction>Exercise 1: Current Sleep Habits (Night 1)
In this exercise, think about the last few nights of sleep. Write the amount of time you slept per night and rate the quality of your sleep on a scale of 1 to 5, with 1 being bad and 5 being great. This will give you snapshot of your current sleep habits.
Example:
Day of Week
Sunday
Time to Bed At Night
11:30 pm
Time in Bed Before As!
leep (estimate)
1 hour
Time Awake in the Morning
6:30 am
Quality of Sleep (1 to 5)
3
Total Time Sleeping
6 hours </direction>
<details>
<text>
<![CDATA[Day of Week]]>
</text>
<blank userAnswer=""/>
<text>
<![CDATA[ Time to Bed At Night]]>
</text>
<blank userAnswer=""/>
<text>
<![CDATA[ Time in Bed Before Asleep (estimate)]]>
</text>
<blank userAnswer=""/>
<text>
<![CDATA[ Time Awake in the Morning]]>
</text>
<blank userAnswer=""/>
<text>
<![CDATA[ Quality of Sleep (1 to 5)]]>
</text>
<blank userAnswer=""/>
<text>
<![CDATA[ Total Time Sleeping]]>
</text>
<blank userAnswer=""/>
</details>
</fillInTheBlankSurveyQuestion>
<fillInTheBlankSurveyQuestion id="{F52AC41C-C149-4B8D-9976-5F380B1A7851}" status="answered">
<direction>Exercise 1: Current Sleep Habits (Night 2)
In this exercise, think about the last few nights of sleep. Write the amount of time you slept per night and rate the quality of your sleep on a scale of 1 to 5, with 1 being bad and 5 being great. This will give you snapshot o!
f your current sleep habits.
Example:
Day of Week
Sunday!
Time to Bed At Night
11:30 pm
Time in Bed Before Asleep (estimate)
1 hour
Time Awake in the Morning
6:30 am
Quality of Sleep (1 to 5)
3
Total Time Sleeping
6 hours </direction>
<details>
<text>
<![CDATA[Day of Week]]>
</text>
<blank userAnswer=""/>
<text>
<![CDATA[ Time to Bed At Night]]>
</text>
<blank userAnswer=""/>
<text>
<![CDATA[ Time in Bed Before Asleep (estimate)]]>
</text>
<blank userAnswer=""/>
<text>
<![CDATA[ Time Awake in the Morning]]>
</text>
<blank userAnswer=""/>
<text>
<![CDATA[ Quality of Sleep (1 to 5)]]>
</text>
<blank userAnswer=""/>
<text>
<![CDATA[ Total Time Sleeping]]>
</text>
<blank userAnswer=""/>
</details>
</fillInTheBlankSurveyQuestion>
<fillInTheBlankSurveyQuestion id="{4F33A341-308C-493E-BF98-E13927064BC5}" status="answered">
<direction>Exercise 1: Current Sleep Habits (Night 3)
In this exercise, think about the last few nights of sleep. Write the amount of time you slept per night and rate the quality of your sleep on a scale of 1 to 5, with 1 !
being bad and 5 being great. This will give you snapshot of your current sleep habits.
Example:
Day of Week
Sunday
Time to Bed At Night
11:30 pm
Time in Bed Before Asleep (estimate)
1 hour
Time Awake in the Morning
6:30 am
Quality of Sleep (1 to 5)
3
Total Time Sleeping
6 hours </direction>
<details>
<text>
<![CDATA[Day of Week]]>
</text>
<blank userAnswer=""/>
<text>
<![CDATA[ Time to Bed At Night]]>
</text>
<blank userAnswer=""/>
<text>
<![CDATA[ Time in Bed Before Asleep (estimate)]]>
</text>
<blank userAnswer=""/>
<text>
<![CDATA[ Time Awake in the Morning]]>
</text>
<blank userAnswer=""/>
<text>
<![CDATA[ Quality of Sleep (1 to 5)]]>
</text>
<blank userAnswer=""/>
<text>
<![CDATA[ Total Time Sleeping]]>
</text>
<blank userAnswer=""/>
</details>
</fillInTheBlankSurveyQuestion>
<fillInTheBlankSurveyQuestion id="{324BFC55-6E6D-48EF-9B0F-341131988317}" status="answered">
<direction>Exercise 1: Current Sleep Habits (Night 4)
In this exercise, think about the last few nights!
of sleep. Write the amount of time you slept per night and rate the qu!
ality of your sleep on a scale of 1 to 5, with 1 being bad and 5 being great. This will give you snapshot of your current sleep habits.
Example:
Day of Week
Sunday
Time to Bed At Night
11:30 pm
Time in Bed Before Asleep (estimate)
1 hour
Time Awake in the Morning
6:30 am
Quality of Sleep (1 to 5)
3
Total Time Sleeping
6 hours </direction>
<details>
<text>
<![CDATA[Day of Week]]>
</text>
<blank userAnswer=""/>
<text>
<![CDATA[ Time to Bed At Night]]>
</text>
<blank userAnswer=""/>
<text>
<![CDATA[ Time in Bed Before Asleep (estimate)]]>
</text>
<blank userAnswer=""/>
<text>
<![CDATA[ Time Awake in the Morning]]>
</text>
<blank userAnswer=""/>
<text>
<![CDATA[ Quality of Sleep (1 to 5)]]>
</text>
<blank userAnswer=""/>
<text>
<![CDATA[ Total Time Sleeping]]>
</text>
<blank userAnswer=""/>
</details>
</fillInTheBlankSurveyQuestion>
<fillInTheBlankSurveyQuestion id="{96C36841-A582-4059-A408-8D8EA0CC09E6}" status="answered">
<direction>Exercise 1: Current Sleep Habits (Night 5)
!
In this exercise, think about the last few nights of sleep. Write the amount of time you slept per night and rate the quality of your sleep on a scale of 1 to 5, with 1 being bad and 5 being great. This will give you snapshot of your current sleep habits.
Example:
Day of Week
Sunday
Time to Bed At Night
11:30 pm
Time in Bed Before Asleep (estimate)
1 hour
Time Awake in the Morning
6:30 am
Quality of Sleep (1 to 5)
3
Total Time Sleeping
6 hours </direction>
<details>
<text>
<![CDATA[Day of Week]]>
</text>
<blank userAnswer=""/>
<text>
<![CDATA[ Time to Bed At Night]]>
</text>
<blank userAnswer=""/>
<text>
<![CDATA[ Time in Bed Before Asleep (estimate)]]>
</text>
<blank userAnswer=""/>
<text>
<![CDATA[ Time Awake in the Morning]]>
</text>
<blank userAnswer=""/>
<text>
<![CDATA[ Quality of Sleep (1 to 5)]]>
</text>
<blank userAnswer=""/>
<text>
<![CDATA[ Total Time Sleeping]]>
</text>
<blank userAnswer=""/>
</details>
</fillInTheBlankSurveyQuestion>
<essayQuestion id="{C91C6866!-63A1-4BE5-84DD-1A0F8C34FB1F}" status="answered">
<direction>Exercise 2:!
Regulate the Body’s Clock through Daily Routine
Some people use a morning routine to help them wake up and a bedtime routine of relaxing activities to prepare their bodies for sleep. These activities of daily living act as “cues†to signal the brain to fall into biological rhythms.
In this exercise, consider for a minute what you did last night before bed and what you’ve done so far today.
Take a moment to describe your daily routine and activities starting with last night.
Evening activities at work, school, community or home: </direction>
<userAnswer>asdfasdf</userAnswer>
</essayQuestion>
<essayQuestion id="{AFE522F8-6D34-4434-BC41-61E7121615FD}" status="answered">
<direction>Relaxing activities before bedtime: </direction>
<userAnswer>asdfsasdf</userAnswer>
</essayQuestion>
<essayQuestion id="{50E422B5-7705-49D6-9CFC-CF1E97389D10}" status="answered">
<direction>
Sleep Routine (time to bed, personal care activities, medication, and time, if awoken): </direction>
<userAnswer>asdfsdfads</userAnswer>
</essayQuestion>
<essayQuestion id="{6DF65956-6976-446F-87DD-02CD0A88FA14}" status="answered">
<direction>Wake up routine (time awake, personal care activities, medication time): </direction>
<userAnswer>asdfdfasdf</userAnswer>
</essayQuestion>
<essayQuestion id="{CF38A3C2-E538-41B1-92C1-15011126231D}" status="answered">
<direction>Morning activities at work, school, community or home: </direction>
<userAnswer>asdfdfasdf</userAnswer>
</essayQuestion>
<essayQuestion id="{CAA971E7-4722-4900-9667-4CF7B283A95C}" status="answered">
<direction>Afternoon activities at work, school, community or home: </direction>
<userAnswer>asdfasdf</userAnswer>
</essayQuestion>
<essayQuestion id="{2A64580E-A99C-4525-8435-2C57ECCBCEFB}" status="answered">
<direction>Exercise 3: Planning for Improvement
In this brief exercise, you’ll consider all that you’ve come to realize about your own habits and routine and take a moment to reflect on some small changes that might!
benefit you.
Use the space below to make a short list of small chang!
es you can make to your own routine that might prevent sleep loss. As you’re doing this, consider some of the following questions:
What changes, if any, have I made in the past that have worked for me? </direction>
<userAnswer>asdfsad</userAnswer>
</essayQuestion>
<essayQuestion id="{6EB6CCF7-045A-4E8B-AFA0-794F00FEB658}" status="answered">
<direction>Are there some changes that have not worked? </direction>
<userAnswer>asdfsasdf</userAnswer>
</essayQuestion>
<essayQuestion id="{99CBF95D-7427-4999-BF93-6D727D607B0A}" status="answered">
<direction>A few small changes I can make to improve my sleep and health: </direction>
<userAnswer>asdfsasdf</userAnswer>
</essayQuestion>
<essayQuestion id="{E3621400-19BD-4200-A8A2-DE6544EFAD65}" status="answered">
<direction>If I make this change, how might it impact my life/Life Goals? </direction>
<userAnswer>asdfasdfa</userAnswer>
</essayQuestion>
很抱歉,如果格式在xml位上搞砸了,但你应该从中得到这个想法。所以xml位是由$ detailed_results_xml生成的,我需要将其中的一些部分解析为html以通过电子邮件发送,但是现在我只看到一个数字1.非常感谢任何帮助!
答案 0 :(得分:1)
print_r返回1(整数)。您必须为其传递第二个布尔参数以返回字符串。
该行是:
$emailtest = print_r($xml);
这就是为什么你得到1作为邮件的$ message参数。可能你发错了消息(email()3rd参数),我想你想要:
mail("email@email.com", $quiz_title, $xml, "From: fromname <noreply@test.com>");
对于解析XML,有很多方法: