求一段php調用txt資料資料並賦值的代碼

來源:互聯網
上載者:User
求一段php調用txt檔案資料並賦值的代碼
首頁檔案 index.html
引用檔案:./txt/pan.txt中的第三行:false或者yes
在index.html中做一個if..else的判斷語句,變數$do的值是pan.txt的第三行中的數值;

這個php該怎麼寫呢?
引用變數 引用txt if...else 判斷語句

分享到:


------解決方案--------------------
$myFile = "./txt/pan.txt";
$lines = file($myFile);//檔案放入數組中
$do = $lines[3]; //line 3

if ($do == "false") {
echo "false, do ..."; //false的做的事情
} elseif ($do == "yes") {
echo "yes, do...."; //yes的時候做的事情
} else {
echo "not supported"; //其他值
}
?>

------解決方案--------------------
寫錯了,剛剛是line 4
$myFile = "./txt/pan.txt";
$lines = file($myFile);//檔案放入數組中
$do = $lines[2]; //line 3

if ($do == "false") {
echo "false, do ..."; //false的做的事情
} elseif ($do == "yes") {
echo "yes, do...."; //yes的時候做的事情
} else {
echo "not supported"; //其他值
}
?>

引用:
$myFile = "./txt/pan.txt";
$lines = file($myFile);//檔案放入數組中
$do = $lines[3]; //line 3

if ($do == "false") {
echo "false, do ..."; //false的做的事情
} elseif ($do == "yes") {
echo "yes, do...."; //yes的時候做的事情
} else {
echo "not supported"; //其他值
}
?>

------解決方案--------------------
你的這個是範本語言?

如果知識輸出,你修改一下,直接echo "
    "就好了,false的情況下不做處理,都不用判斷,就判斷是否為yes

    引用:
    其實要輸出是這麼一個
      ,如果do的值為yes 就輸出,為false就不輸出,請問這個怎麼實現呢?
          


        {query:name=commend_goods as co join=left join goods as go on co.goods_id eq go.id where=co.commend_id eq 1 and go.is_del eq 0 AND go.id is not null fields=go.list_img,go.sell_price,go.name,go.market_price,go.id limit=7 order=id desc group = id}
        {set:$tmpId=$item['id'];}





      • {$item['name']}


        RMB{$item['sell_price']}



      • {/query}




      Quote: 引用:

      寫錯了,剛剛是line 4
      $myFile = "./txt/pan.txt";
      $lines = file($myFile);//檔案放入數組中
      $do = $lines[2]; //line 3

      if ($do == "false") {
      echo "false, do ..."; //false的做的事情
      } elseif ($do == "yes") {
      echo "yes, do...."; //yes的時候做的事情
      } else {
      echo "not supported"; //其他值
      }
      ?>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.