久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    <bdo id='MPDFB'></bdo><ul id='MPDFB'></ul>
<legend id='MPDFB'><style id='MPDFB'><dir id='MPDFB'><q id='MPDFB'></q></dir></style></legend>
  • <tfoot id='MPDFB'></tfoot>
    <i id='MPDFB'><tr id='MPDFB'><dt id='MPDFB'><q id='MPDFB'><span id='MPDFB'><b id='MPDFB'><form id='MPDFB'><ins id='MPDFB'></ins><ul id='MPDFB'></ul><sub id='MPDFB'></sub></form><legend id='MPDFB'></legend><bdo id='MPDFB'><pre id='MPDFB'><center id='MPDFB'></center></pre></bdo></b><th id='MPDFB'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='MPDFB'><tfoot id='MPDFB'></tfoot><dl id='MPDFB'><fieldset id='MPDFB'></fieldset></dl></div>
  • <small id='MPDFB'></small><noframes id='MPDFB'>

        從文本文件中獲取數(shù)據(jù)并將其顯示在 html 表中

        Getting data from text file and display it in html table(從文本文件中獲取數(shù)據(jù)并將其顯示在 html 表中)

        • <legend id='7HgtP'><style id='7HgtP'><dir id='7HgtP'><q id='7HgtP'></q></dir></style></legend>
            • <bdo id='7HgtP'></bdo><ul id='7HgtP'></ul>
                <tbody id='7HgtP'></tbody>

                  <small id='7HgtP'></small><noframes id='7HgtP'>

                  <i id='7HgtP'><tr id='7HgtP'><dt id='7HgtP'><q id='7HgtP'><span id='7HgtP'><b id='7HgtP'><form id='7HgtP'><ins id='7HgtP'></ins><ul id='7HgtP'></ul><sub id='7HgtP'></sub></form><legend id='7HgtP'></legend><bdo id='7HgtP'><pre id='7HgtP'><center id='7HgtP'></center></pre></bdo></b><th id='7HgtP'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='7HgtP'><tfoot id='7HgtP'></tfoot><dl id='7HgtP'><fieldset id='7HgtP'></fieldset></dl></div>
                  <tfoot id='7HgtP'></tfoot>
                  本文介紹了從文本文件中獲取數(shù)據(jù)并將其顯示在 html 表中的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我為每一行得到了一個這種模式的文本文件:

                  I got a text file in this pattern for each line:

                  Username : Score
                  

                  我正在嘗試用它創(chuàng)建一個記分牌.

                  I'm trying to create a scoreboard out of this.

                  這是我的嘗試:

                  <table width="200" border="1">
                    <tr>
                      <td width="85">Nom</td>
                      <td width="99">Score</td>
                    </tr>
                    <tr>
                      <td height="119"></td>
                      <td></td>
                    </tr>
                  </table>

                  問題是如何將每個 usernamescore 復制到表中(沒有 : 字符)?

                  The question is how can I copy each username and score to the table (without the : character) ?

                  我當前的 php 代碼:

                  My current php code:

                  <?php 
                  
                      $file = file_get_contents('facile.txt', true);
                      $arr = explode("/", $file, 2);
                      $first = $arr[0];
                  
                  ?>
                  

                  這只會給我第一個用戶名,但我想獲取每一行的所有用戶名.

                  This will give me only the first username, but I want to get all the usernames from every line.

                  推薦答案

                  這應該適合你:

                  這里我首先使用 file() 其中每一行都是一個數(shù)組元素.在那里我忽略每行末尾的空行和換行符.

                  Here I first get all lines into an array with file() where every line is one array element. There I ignore empty lines and new line characters at the end of each line.

                  在此之后,我使用 array_map()并使用explode(),然后我將其作為數(shù)組返回以創(chuàng)建一個多維數(shù)組,例如:

                  After this I go through each line with array_map() and extract the username + score with explode(), which I then return as array to create a multidimensional array, e.g:

                  Array
                  (
                      [0] => Array
                          (
                              [username] => a
                              [score] => 5
                          )
                      //...
                  

                  我用 usort()(要將順序從 ASC 更改為 DESC,您只需將 > 更改為 <> 在 usort()) 之后,我簡單地遍歷數(shù)據(jù)并將其打印在表格中.

                  The I sort the array by the score with usort() (To change the order from ASC to DESC you can just change > to < in usort()) and after this I simply loop through the data and print it in the table.

                  <?php 
                  
                      $lines = file("scores.txt", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
                      $data = array_map(function($v){
                          list($username, $score) = explode(":", $v);
                          return ["username" => $username, "score" => $score];
                      }, $lines);
                  
                      usort($data, function($a, $b){
                          if($a["score"] == $b["score"])
                              return 0;
                          return $a["score"] > $b["score"] ? 1 : -1;
                      });
                  
                  ?>
                  
                  <table width="200" border="1">
                      <tr>
                          <td width="85">Nom</td>
                          <td width="99">Score</td>
                      </tr>
                  <?php foreach($data as $user){ ?>
                      <tr>
                          <td height="119"><?php echo $user["username"]; ?></td>
                          <td><?php echo $user["score"]; ?></td>
                      </tr>
                  <?php } ?>
                  </table>
                  

                  輸出:

                  Nom   Score  // Nom   Score
                   e      2    //  d     123
                   a      5    //  c     26
                   b     15    //  b     15
                   c     26    //  a      5
                   d    123    //  e      2
                  

                  這篇關于從文本文件中獲取數(shù)據(jù)并將其顯示在 html 表中的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯(lián)系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  Deadlock exception code for PHP, MySQL PDOException?(PHP、MySQL PDOException 的死鎖異常代碼?)
                  PHP PDO MySQL scrollable cursor doesn#39;t work(PHP PDO MySQL 可滾動游標不起作用)
                  PHP PDO ODBC connection(PHP PDO ODBC 連接)
                  Using PDO::FETCH_CLASS with Magic Methods(使用 PDO::FETCH_CLASS 和魔術方法)
                  php pdo get only one value from mysql; value that equals to variable(php pdo 只從 mysql 獲取一個值;等于變量的值)
                  MSSQL PDO could not find driver(MSSQL PDO 找不到驅動程序)
                    <tbody id='TWvPz'></tbody>

                  • <bdo id='TWvPz'></bdo><ul id='TWvPz'></ul>

                    <small id='TWvPz'></small><noframes id='TWvPz'>

                    <legend id='TWvPz'><style id='TWvPz'><dir id='TWvPz'><q id='TWvPz'></q></dir></style></legend>
                    <i id='TWvPz'><tr id='TWvPz'><dt id='TWvPz'><q id='TWvPz'><span id='TWvPz'><b id='TWvPz'><form id='TWvPz'><ins id='TWvPz'></ins><ul id='TWvPz'></ul><sub id='TWvPz'></sub></form><legend id='TWvPz'></legend><bdo id='TWvPz'><pre id='TWvPz'><center id='TWvPz'></center></pre></bdo></b><th id='TWvPz'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='TWvPz'><tfoot id='TWvPz'></tfoot><dl id='TWvPz'><fieldset id='TWvPz'></fieldset></dl></div>

                        <tfoot id='TWvPz'></tfoot>

                          • 主站蜘蛛池模板: 一区二区三区免费 | 欧美lesbianxxxxhd视频社区 | 国产精品久久久久久吹潮日韩动画 | 欧美日韩毛片 | 亚洲精选一区二区 | 久久久精品综合 | 欧美一二三 | 午夜电影福利 | 国产精品九九视频 | 成人h动漫亚洲一区二区 | 成人精品一区亚洲午夜久久久 | 久久99精品久久久久蜜桃tv | 中文字幕视频在线 | 国产在线观看一区二区 | 成人深夜福利 | 国产精品不卡 | 亚洲高清三级 | 国产综合精品 | 91.色 | 日本在线精品视频 | 久热久 | 91精品国产综合久久久久久丝袜 | 拍拍无遮挡人做人爱视频免费观看 | 欧美精品乱码久久久久久按摩 | 免费a在线 | 91色综合| 久久国产精品久久久久久 | 91精品久久久久久久久 | hitomi一区二区三区精品 | 国产永久免费 | .国产精品成人自产拍在线观看6 | 欧美一二三四成人免费视频 | 成人免费网站 | 免费一区二区三区 | 99综合| 亚洲乱码一区二区三区在线观看 | 懂色av色香蕉一区二区蜜桃 | 91精品中文字幕一区二区三区 | 成人免费视频网 | 国产精品一区二区久久 | 一级在线 |