简体   繁体   English

尝试在javascript中的php中添加新行

[英]Trying To Add New Lines In php inside of javascript

Im still trying to get used to javascript and php so hopefully it isn't a noob mistake. 我仍然想习惯于javascript和php,所以希望这不是菜鸟的错误。 Ok So after looking around other posts posted here I still can't find how to make a new line. 确定,所以在浏览了此处发布的其他帖子之后,我仍然找不到如何换行的方法。 What I mean by this is the following, 我的意思是,

1°/ 1°/ 在此处输入图片说明 2°/ 2°/ 在此处输入图片说明 3°/ 3°/ 在此处输入图片说明 4°/ 4°/ 在此处输入图片说明

*just as a quick side note in the above images you can see three red boxes and inside the 3 red boxes is in this case the Callsign Of the person and The Aircraft they are flying. *就像上面图片中的简短提示一样,您可以看到三个红色框,在这三个红色框内是本人和他们正在飞行的飞机的呼号。 The data is being pulled from a XML file with no issue. 从XML文件中提取数据没有问题。

But what I am struggling with is Having 1 Callsign And 1 Aircraft Per line. 但是我正在努力的是每条线配备1个呼号和1架飞机。

        var board = new DepartureBoard (document.getElementById ('test'), { rowCount: 10, letterCount: 40 }); 
        board.setValue (['<?php 
            $EGLL = simplexml_load_file('EGLL.xml');
            foreach($EGLL as $info) {
                echo $info->callsign . " "  .  $info->aircraft . " " ;
            }
            ?>'])

    </script>
    <?php
    file_put_contents("EGLL.xml",         fopen("http://api.vateud.net/online/departures/EGLL.xml", 'r'));
    ?>
    <script src="http://code.jquery.com/jquery-latest.js"
    type="text/javascript"></script>

So That is the code that I am using to get the data Onto the Board but when I add a for example \\n or echo nl2br it just returns back with a blank webpage. 这就是我用来将数据存储到板上的代码,但是当我添加例如\\ n或echo nl2br时,它只是返回一个空白网页。 Picture 2 Shows What I See and also in that picture I show where exactly I put the \\n and i also tried it with the echo nl2br I get the exactly same white screen. 图片2显示了我所看到的内容,并且在该图片中还显示了我将\\ n放在什么位置,并且还使用echo nl2br对其进行了尝试,得到了完全相同的白屏。 Aswell in that picture It shows All the Callsign's And Aircraft's in a vertical List unlike when I remove the \\n its all horizontal like picture 4 Hopefully the 4 Pictures in the 1 link didn't confuse but I need 10 Rep points in order to post 2 or more :/ But hopefully you understand what I am trying to do. 在该图片中,它在垂直列表中显示了所有呼号和飞机,这与我删除\\ n时一样,如图片4所示。希望1链接中的4张图片不会造成混淆,但我需要10个Rep点才能发布2个或更多:/但希望您理解我正在尝试做的事情。 Thanks - Ciaran 谢谢-西亚兰

You should send the values to form a javascript array. 您应该发送值以形成javascript数组。 Watch for the ' location (one per item): 留意'位置(每项一个):

<?php
  $EGLL = simplexml_load_file('EGLL.xml');
?>

<script>
  var board = new DepartureBoard (document.getElementById ('test'), { rowCount: 10, letterCount: 40 }); 
  board.setValue ([
    <?php 
      foreach($EGLL as $info) {
        echo "'" . $info->callsign . " "  .  $info->aircraft . "'," ;
      }
    ?>
  ]);
</script>

This should generate the javascript code as follows, which you can corroborate by viewing your webpage sourcecode: 这应生成如下所示的javascript代码,您可以通过查看网页源代码进行确认:

board.setValue(['AAL7422 B752','AIC234 B738L']);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM