用PHP解析返回数字1的电子邮件的XML


Parse XML with PHP for email returning the number 1

我正在使用一个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="answerswered">
      <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="answerswered">
  <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="answerswered">
  <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="answerswered">
  <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="answerswered">
  <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="answerswered">
  <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="answerswered">
  <direction>Relaxing activities before bedtime: </direction>
  <userAnswer>asdfsasdf</userAnswer>
</essayQuestion>
  <essayQuestion id="{50E422B5-7705-49D6-9CFC-CF1E97389D10}" status="answerswered">
  <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="answerswered">
  <direction>Wake up routine (time awake, personal care activities, medication time): </direction>
  <userAnswer>asdfdfasdf</userAnswer>
</essayQuestion>
  <essayQuestion id="{CF38A3C2-E538-41B1-92C1-15011126231D}" status="answerswered">
  <direction>Morning activities at work, school, community or home: </direction>
  <userAnswer>asdfdfasdf</userAnswer>
</essayQuestion>
  <essayQuestion id="{CAA971E7-4722-4900-9667-4CF7B283A95C}" status="answerswered">
  <direction>Afternoon activities at work, school, community or home: </direction>
  <userAnswer>asdfasdf</userAnswer>
</essayQuestion>
<essayQuestion id="{2A64580E-A99C-4525-8435-2C57ECCBCEFB}" status="answerswered">
  <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="answerswered">
  <direction>Are there some changes that have not worked? </direction>
  <userAnswer>asdfsasdf</userAnswer>
</essayQuestion>
<essayQuestion id="{99CBF95D-7427-4999-BF93-6D727D607B0A}" status="answerswered">
  <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="answerswered">
  <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。非常感谢您的帮助!

print_r返回1(整数)。您必须传递第二个布尔参数,它才能返回字符串。

线路是:

$emailtest = print_r($xml);

这就是为什么您将1作为邮件的$message参数。可能你发送了错误的信息(email()第三个参数),我想你会想:

mail("email@email.com", $quiz_title, $xml, "From: fromname <noreply@test.com>");

解析XML有很多方法:

功能

面向对象