当前位置:Gxlcms > PHP教程 > 求一段php调用txt文件数据并赋值的代码

求一段php调用txt文件数据并赋值的代码

时间:2021-07-01 10:21:17 帮助过:23人阅读

引用变量 引用txt if...else 判断语句

首页文件 index.html
引用文件:./txt/pan.txt中的第三行:false或者yes
在index.html中做一个if..else的判断语句,变量$do的值是pan.txt的第三行中的数值;

这个php该怎么写呢?


回复讨论(解决方案)

  1. <!--?php$myFile = "./txt/pan.txt";$lines = file($myFile);//文件放入数组中$do = $lines[3]; //line 3if ($do == "false") { echo "false, do ..."; //false的做的事情} elseif ($do == "yes") { echo "yes, do...."; //yes的时候做的事情} else { echo "not supported"; //其他值}?-->

写错了,刚刚是line 4

  1. <!--?php$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"; //其他值}?-->

  1. <!--?php$myFile = "./txt/pan.txt";$lines = file($myFile);//文件放入数组中$do = $lines[3]; //line 3if ($do == "false") { echo "false, do ..."; //false的做的事情} elseif ($do == "yes") { echo "yes, do...."; //yes的时候做的事情} else { echo "not supported"; //其他值}?-->

thank you!不过如果要输出的不是一句话而是一个div层呢?该怎么做呢?
写错了,刚刚是line 4

  1. <!--?php$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"; //其他值}?-->

其实要输出是这么一个

    ,如果do的值为yes 就输出,为false就不输出,请问这个怎么实现呢?
    1. <ul>
    2. {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}
    3. {set:$tmpId=$item['id'];}
    4. <li>
    5. <span class="goods_img">
    6. <img src="https://www.gxlcms.com/{webroot:$item[list_img]}" alt="{$item['name']}"> </span>
    7. <h3 class="item_name">{$item['name']}</h3>
    8. <p><span class="moneda">RMB</span><span class="sell_price">{$item['sell_price']}</span></p>
    9. </li>
    10. {/query}
    11. </ul>



    写错了,刚刚是line 4
    1. <!--?php$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"; //其他值}?-->

    你的这个是模板语言?

    如果知识输出,你修改一下,直接echo "

      "就好了,false的情况下不做处理,都不用判断,就判断是否为yes

      其实要输出是这么一个
        ,如果do的值为yes 就输出,为false就不输出,请问这个怎么实现呢?
        1. <ul>
        2. {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}
        3. {set:$tmpId=$item['id'];}
        4. <li>
        5. <span class="goods_img">
        6. <img src="https://www.gxlcms.com/{webroot:$item[list_img]}" alt="{$item['name']}"> </span>
        7. <h3 class="item_name">{$item['name']}</h3>
        8. <p><span class="moneda">RMB</span><span class="sell_price">{$item['sell_price']}</span></p>
        9. </li>
        10. {/query}
        11. </ul>




        写错了,刚刚是line 4
        1. <!--?php$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"; //其他值}?-->

        OK 谢谢!
        你的这个是模板语言?

        如果知识输出,你修改一下,直接echo "

          "就好了,false的情况下不做处理,都不用判断,就判断是否为yes

人气教程排行