having issue with the explode, i have simple text file and each line is end with number. i just want to extract end of line number and create same number of sub stings. i tried to use explode function but unable to retrieve only end of string number. following is .txt file structure and my code with expected result.
‘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/>";
}
?
Output:
a1
- sub string
- sub string
- sub string
a2
1. sub string
2. sub string
a3
1. sub string
2. sub string
3. sub string
4. sub string
You could also just use substr()
echo substr(trim($line), -1);Tho I would do it like: