爆発に問題があるので、単純なテキストファイルがあり、各行は数字で終わります。行末番号を抽出して、同じ数のサブスティングを作成したいだけです。explode関数を使用しようとしましたが、文字列番号の末尾のみを取得できませんでした。以下は、.txtファイルの構造と期待される結果を示す私のコードです。
'text.txt'
a1 bbb ccc 111-111 ddd eee 3
a2 fff ccc(123-12312)111-111 ddd eee 2
a3 bbb aaa(32 32)111-111 ddd eee 4
<?php
$file = "C:\\test.txt";
$f = fopen($file, "r");
while ( $line = fgets($f, 1000) ) {
print "<br/>";
$pieces = explode(" ", $line);
print $line;
print "<br/>";
print "<\t>";
for(i=0; i>=$pieces[5];i++)
{
print "<br/>";
print "<\t>";
}
print "<br/>";
}
?
出力:
a1
- サブ文字列
- サブ文字列
- サブ文字列
a21
.サブ文字列
2.サブ文字列
a31
.サブストリング
2.サブストリング
3.サブストリング
4.サブストリング