-2

我的程序的目标:将一个大字符串拆分为一个字符串数组,每个字符串包含子字符串“区域”之间的文本段,以及下一次出现的同一子字符串。

我尝试了什么:

#Get file into a string
$filecont=file_get_contents($filename);
#Count all occurences of the substring, and get the positions of the substring into the array $arr
$arr=strallpos($filecont,"zone",0);
#The function strallpos does its job. The array $arr is now:
#Array ( [0] => 70 [1] => 148 [2] => 197 [3] => 316 [4] => 500 [5] => 637 [6] => 709 [7] => 748 [8] => 867 [9] => 878 [10] => 940 [11] => 990 [12] => 1154 [13] => 1321 [14] => 1440 [15] => 1561 [16] => 1684 [17] => 1695 [18] => 1759 [19] => 1811 [20] => 1926 [21] => 2045 [22] => 2168 [23] => 2285 )
#Find and return the substring
for ($i=0;($i+1)<=count($arr);$i++)
{       
    #Line 53 follows
    print (substr ($filecont,$arr($i),($arr($i+1)-$arr($i))));      
}

我得到的错误是:Fatal error: Function name must be a string in C:\wamp\www\dns.php on line 53

我究竟做错了什么?我想要一些关于错误代码的指针。

4

1 回答 1

2

解决方案似乎是您需要使用explode,如:

$zones = explode("zone", $filecont);

这将在 $zones 中存储一个数组,其中包含单词“zone”之间的所有字符串。试试看它是否有效:)

于 2013-07-17T09:21:01.857 回答