脚本宝典收集整理的这篇文章主要介绍了如何在PHP中用空格匹配文本文件中的两到三个单词,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
John Doe,123 Main St,400.00,01/01/2016,Jane Doe,124 Main St,300.00,John Doe,01/03/2016,200.00
<?PHP $lines = file('data.txt'); //here's the filename ?> <center> <table id="historytable" width="640" border="1"> <caption>Billing & Payment History </caption> <tbody> <tr> <td width="40">Tenant</td> <td width="40">Address</td> <td width="40">Date</td> <td width="40">Rent</td> <td width="40">Payment</td> </tr> <?PHP $search = $_POST["name"]; //assigning a string to each piece of input data // Store true when the text is found $balance = 0; //assign initial value to balance $renttotal = 0; //assign initial value to renttotals $received = 0; //assign initial value to received $found = false; foreach ($lines as $line) { //this is the loop to read the txt file { if(strpos($line,$search) !== false) { $found = true; list($a,$b,$c,$d,$e) = explode(',',$line); //this assigns a variable name to each data item separated by a comma $renttotal+= $c; //each time it loops,it gathers the value of c adding it to itself same for the two lines below $received+= $e; $balance = $renttotal - $received; //subtracts the final value of renttotal and received assigning the difference to balance $line_array = explode(",",$line); //breaks each piece of data apart to be placed in a table } echo "<tr> <td width=40>$a</td> <td width=40>$b</td> <td width=40>$c</td> <td width=40>$d</td> <td width=40>$e</td> </tr>"; }}} ?> </tbody> </table> </center> <BR /> <BR /> <center> <p>TOTAL RENTS CHARGED $<?PHP echo "$renttotal"?><br /> TOTAL PAYMENTS RECEIVED $<?PHP echo "$received"?><br /> BALANCE DUE $<?PHP echo "$balance"?></p>
预先感谢您的任何帮助.
以上是脚本宝典为你收集整理的如何在PHP中用空格匹配文本文件中的两到三个单词全部内容,希望文章能够帮你解决如何在PHP中用空格匹配文本文件中的两到三个单词所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。