【发布时间】:2013-07-17 09:12:24
【问题描述】:
我的程序的目标:将一个大字符串拆分为一个字符串数组,每个字符串包含子字符串“区域”之间的文本段,以及下一次出现的相同子字符串。
我尝试了什么:
#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
我做错了什么?我想要一些关于错误代码的指针。
【问题讨论】:
-
你尝试获取字符串还是字符串的位置?
-
我已经得到了子字符串的位置,以数组$arr的形式,它的每个值都包含了字符串出现的位置。现在我正在尝试返回这些位置之间的字符串段。
-
()调用函数,[]访问数组索引。