dongzanxun2790 2012-02-03 19:18
浏览 157
已采纳

我的PHP中出现“意外的T_STRING”错误?

I'm having a problem with some PHP code I'm trying to use. I keep getting an "unexpected T_STRING" error? This is the code on my test page:

   <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
   <html xmlns="http://www.w3.org/1999/xhtml">

    <?php
    include 'http://www.weather.gov/xml/current_obs/KTPA.xml';

    $current_observation = new SimpleXMLElement($xmlstr);

    echo $current_observation->location[0]->plot;
    echo $current_observation->weather[0]->plot;
    echo $current_observation->temperature_string[0]->plot;
    echo $current_observation->wind_string[0]->plot;

    ?>

What I'm wanting to do is pull weather data from this National Weather Service XML file, and display it in a way similar to how the NWS is doing it on that page. However, the above code returns this message: "Parse error: syntax error, unexpected T_STRING in http://www.weather.gov/xml/current_obs/KTPA.xml on line 1". Is this something I can fix? I'm new to PHP, so any help you can provide will be appreciated.

  • 写回答

5条回答 默认 最新

  • dopzc64662 2012-02-03 19:27
    关注

    First of all this script should be run before the html and doctype tags, you did not finish your html code with head and body Those should always be the basic for your html webpage.

    Second of all where does $xmlstr points to, you have never created the variable $xmlstr, and the webpage you include is xml so that one doesn't do it either. If you are using your own set up webserver you could enable cUrl where you can parse the xml sourcecode, saving it into variables and showing it step by step using an array and a for-loop. You would save the parsed data in an array like:

    with cUrl you get an output which you can save in a variable, lets say $output. from there on you would have to echo your way parsing step by step, so first you would do echo $output; so you know what the source actually looks like when using cUrl, next step is to find the specific data in that url and parse your way to that point using explode (creates arrays) and substrings, and you can save those into an array like: $city[$cityName][$temp] or someting like that

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器