Maison >développement back-end >tutoriel php >求一段php调用txt文件数据并赋值的代码
引用变量 引用txt if...else 判断语句
首页文件 index.html
<?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
<?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"; //其他值}?>
<?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
<?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"; //其他值}?>
其实要输出是这么一个
<ul> {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'];} <li> <span class="goods_img"> <a href="{url:/site/products/id/$tmpId}" target="_blank"> <img src="{webroot:$item[list_img]}" alt="{$item['name']}" /> </a></span> <h3 class="item_name">{$item['name']}</h3> <p><span class="moneda">RMB</span><span class="sell_price">{$item['sell_price']}</span></p> </li> {/query} </ul>
<?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 "
<ul> {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'];} <li> <span class="goods_img"> <a href="{url:/site/products/id/$tmpId}" target="_blank"> <img src="{webroot:$item[list_img]}" alt="{$item['name']}" /> </a></span> <h3 class="item_name">{$item['name']}</h3> <p><span class="moneda">RMB</span><span class="sell_price">{$item['sell_price']}</span></p> </li> {/query} </ul>
<?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 "