i need to extract all words that begin with "a" in file linux.words but i started to write code in php but i have problem i receive all words that contain "a" ,how to fix it ? <?php $str=a; $counter=0; $content=file("linux.words"); foreach ($content as $line) { $d=strpos($line,"a"); if($d==1){ echo $line."<br>"; $counter++; } } echo "counter=".$counter."<br>"; ?>
<?php $counter=0; $content=file("linux.words"); foreach ($content as $line) { $words = explode(' ', $line); // Split a line by the delimiter "spacer" for ($i=0; $i < count($words) ; $i++) { if($words[$i][0]=="a") { // First letter of each word echo $words[$i]."<br />"; $counter++; } } } echo "counter=".$counter."<br>"; ?> PHP: