简体   繁体   中英

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. 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°/ 在此处输入图片说明 2°/ 在此处输入图片说明 3°/ 在此处输入图片说明 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.

But what I am struggling with is Having 1 Callsign And 1 Aircraft Per line.

        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. 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. 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. Thanks - Ciaran

You should send the values to form a javascript array. 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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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