<?php $file = fopen("verylongword.txt", "r"); /* inside verylongword.txt abdbbaabaadbbadabdaddaabbabdabdbbaabaadbbadabdaddaabbabdabdbbaabaadbbadabdaddaabbabdabdbbaabaadbbadabdaddaabbabdabdbbaabaadbbadabdaddaabbabd abdbbaabaadbbadabdaddaabbabdabdbbaabaadbbadabdaddaabbabdabdbbaabaadbbadabdaddaabbabdabdbbaabaadbbadabdaddaabbabdabdbbaabaadbbadabdaddaabbabd */ $word = ""; while(!feof($file)) { $line = fgets($file); $word .= trim($line); } fclose($file); $subseq = null; $count = 0; // how write code count number of instances of subsequence in word string // want count how many abd in verylongword.txt print $subseq . " shows " . $count . " times <br/>"; ?>
there's function that: substr_count
$contentsofverylongword = file_get_contents("verylongword.txt"); $count = substr_count($contentsofverylongword, 'abd');
Comments
Post a Comment