dongtanliefang8765
dongtanliefang8765
2017-04-08 09:06

在网页中截断来自php的输出

已采纳

I want to get the list of trams coming by my house. I have a python script that takes the times and spits them out. On every line there is the tram number , the next one is then on a new line.

$ /var/www/html/kvvliveapi.py departures de:8212:31
sofort  S1 Bad Herrenalb||||

1 min   3 Heide||||

1 min   3 Tivoli über Hbf||||

3 min   S2 Spöck||||

3 min   2 Wolfartsweier||||

I want to have this in a web page, so I run the script with php.

(in index.html)

<?php 
exec('python /var/www/html/kvvliveapi.py departures de:8212:31', $out);
echo implode("
", $out);
?> 

But then on the webpage it looks really weird. It doesn't have all the lines it has, when I run it in the terminal, and although I have new lines, on the web page everything is on one line.

sofort S1 Bad Herrenalb|||| 1 min 3 Heide||||
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • doulongsha5478 doulongsha5478 4年前

    This same worked for me

    Solution 1:

    Change this to

    echo implode("
    ", $out);
    

    This:

    print_r(implode("<br>",$out));
    

    Solution2:

    Change this to:

    echo implode("
    ", $out);
    

    This:

    echo "<pre>";
    echo implode("
    ", $out);
    echo "</pre>";
    
    点赞 评论 复制链接分享