PHP命运脚本

PHP命运脚本,php,arrays,file,Php,Arrays,File,我目前正在为我的大型PHP项目编写类似《财富》的子模块,我的问题是为什么它不能正常工作。(此外,我正在寻找更合适的方法) file.php <? $file = file_get_contents("pytania.txt", true); $number = substr_count($file ,"##")-1; preg_match_all("/##(.*?)##/si", $file, $matches); for($i=0;$i<$number;$i++){ echo(

我目前正在为我的大型PHP项目编写类似《财富》的子模块,我的问题是为什么它不能正常工作。(此外,我正在寻找更合适的方法)

file.php

<?
$file = file_get_contents("pytania.txt", true);
$number = substr_count($file ,"##")-1;

preg_match_all("/##(.*?)##/si", $file, $matches);

for($i=0;$i<$number;$i++){
echo($matches[1][$i]."<br><br>");
}
?>
我遇到的主要问题是,第二(2/3)份财富甚至没有显示出来。有什么线索吗?想法?

解决方案:

<?
$file = file_get_contents("pytania.txt", true);
$number = substr_count($file ,"##")-1;

$a = explode('##', $file);

for($i=1;$i<=$number;$i++){
    echo $a[$i]."<br><br>";
}

您也可以使用
foreach()
循环。(我认为这更适合这个)

$file=explode(“##,$s);
foreach($file as$item){
回显$item。“

”; }
为什么要使用正则表达式?只需使用
explode
。遵循您的想法。谢谢
<?
$file = file_get_contents("pytania.txt", true);
$number = substr_count($file ,"##")-1;

$a = explode('##', $file);

for($i=1;$i<=$number;$i++){
    echo $a[$i]."<br><br>";
}
$file = explode('##', $s);

foreach($file as $item) {
    echo $item . "<br /><br >";
}