Home > Backend Development > PHP Tutorial > 一个很简单的匹配有关问题

一个很简单的匹配有关问题

WBOY
Release: 2016-06-13 09:59:00
Original
742 people have browsed it

一个很简单的匹配问题
-------------文本---------------

Name1 A B C
Name2 A B C
Name3 A B C

-------------文本---------------


A、B、C是3个随机数字,有时某个数字会为空(即变为 Name1 A C),请问如何才能在任何情况下取到ABC三个位置的值呢?
谢谢!

------解决方案--------------------

PHP code
$s = <font color="#e78608">------解决方案--------------------</font><br>嘿嘿...<br><br>a.php<br>-------------文本---------------<br><br>Name1 11 23 14<br>Name2 43    33<br>Name3 30 44    2<br><br>-------------文本---------------<br>b.php<br><br><?php <br />$file = "a.php"; // 变量赋值<br>$fp = fopen ( $file, "r" ); // 以只读方式打开文件<br>$i = 0; // i=0<br>while ( ! feof ( $fp ) ) { // while循环,条件:没到文件的末端。<br>	$buffer = fgets ( $fp, 4096 ); // fgets() 函数用于从文件中逐行读取文件,,读取的字节数。默认是 1024 字节。<br>	preg_replace ( '/ +/', ' ', $buffer );<br>	preg_match_all ( '/ ([0-9]+)/', $buffer, $matches );<br>	if (! empty ( $matches [1] )) {<br>		print_r ( $matches [1] );<br>	}<br>	$i = $i + 1; // 通过while循环,带动i值递增,实现数组构建。<br>}<br>fclose ( $fp ); // 关闭文件。<br>?><br><font color="#e78608">------解决方案--------------------</font><br>其实还有我觉得还有一个比较大的疑问!因为LZ要的是数字和字母,比如:<br>文本:<br>Name1:11     32<br>我最后取出来的是<br>
Copy after login
PHP code
Array(     [0]=11     [1]=     [2]=32)<div class="clear">
                 
              
              
        
            </div>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template