how can i make my php code shorter?
<p>can some one please give me advice on how I make this block of code considerably shorter?</p>

<p>What it does is get data from a text file uploaded onto the server. It reads the file and it looks for 3 keywords. I placed each keyword in an array, then it outputs the entire line where the keyword is found in. Then in the foreach statemens i loops through it and echo out the line (for debugging purposes, but when complete I would not like it to echo the line but rather just do the count) then it counts all the instances of the keyword. In the end I echo out the number of occurances. I feel that this can be done more efficiently and organized.</p>

<p><code>$sf-&gt;countLines()</code> refers to a class I made that handles small operations, in this case I was able to count the number of lines in the file uploaded by the user. I'll in the end compile my script and make one class from it. But for now I'm learning and tinkering around to see how this can be done smoothly.</p>

<pre><code>$_ = NULL;
$msg = "&lt;br /&gt;[ Your Script ".$handle-&gt;file_dst_name_body." has been uploaded ]&lt;br /&gt;";
$file = $handle-&gt;file_dst_path.$handle-&gt;file_dst_name_body.'.'.$handle-&gt;file_dst_name_ext;
$open = fopen($file, 'r+');
$story = utf8_decode(fread($open, filesize($file)));

echo $msg.'&lt;br /&gt;';

$sf = new TextFileReader($file);
$sf-&gt;seekLine(1); // Go to line 1

echo "Total number of lines: ".$sf-&gt;countLines()."&lt;br /&gt;";
if(preg_match_all('/\s{68}(.*)/m', $story, $_))
{
    $unique_pages = array_unique(array_map(create_function('$a', 'return ucfirst(strtolower(trim($a)));'), $_[1]));
    echo "&lt;span&gt;&lt;strong&gt;Pages: &lt;/strong&gt;".count($unique_pages)."&lt;/span&gt;&lt;br /&gt;";
}
$searchfor = array();
$searchfor[0] = 'INT.';
$searchfor[1] = 'EXT.';
$searchfor[2] = 'I/E.';

// get the file contents, assuming the file to be readable (and exist)
$contents = mb_convert_encoding(file_get_contents($file), "UTF-8", "auto");
// escape special characters in the query
$pattern = preg_quote($searchfor[0], '/');
// finalize the regular expression, matching the whole line
$pattern = "/^.*$pattern.*\$/m";

$list = "";
$numInt  = 0;
// search, and store all matching occurences in $matches
if(preg_match_all($pattern, $contents, $matches))
{
    $list = "&lt;ol&gt;";
    foreach($matches as $match) {
        $list .= "&lt;li&gt;&lt;div class='int'&gt;".implode("&lt;/div&gt;&lt;/li&gt;&lt;li&gt;&lt;div class='int'&gt;", $match)."&lt;/div&gt;&lt;/li&gt;\n";
    }
    $numInt = count($matches[0]);
    $list .= "&lt;/ol&gt;";
}else{
    $list = "No matches found";
}

// escape special characters in the query
$pattern2 = preg_quote($searchfor[1], '/');
// finalize the regular expression, matching the whole line
$pattern2 = "/^.*$pattern2.*\$/m";
$list2 = "";
$numExt  = 0;
// search, and store all matching occurences in $matches
if(preg_match_all($pattern2, $contents, $matches2))
{
    $list2 = "&lt;ol&gt;";
    foreach($matches2 as $match) {
        $list2 .= "&lt;li&gt;&lt;div class='int'&gt;".implode("&lt;/div&gt;&lt;/li&gt;&lt;li&gt;&lt;div class='int'&gt;", $match)."&lt;/div&gt;&lt;/li&gt;";
    }
    $numExt = count($matches2[0]);
    $list2 .= "&lt;/ol&gt;";
}else{
    $list2 = "No matches found";
}

// escape special characters in the query
$pattern3 = preg_quote($searchfor[2], '/');
// finalize the regular expression, matching the whole line
$pattern3 = "/^.*$pattern3.*\$/m";
$list3 = 0;
$numIe = 0;
// search, and store all matching occurences in $matches
if(preg_match_all($pattern3, $contents, $matches3))
{
    $list3 = "&lt;ol&gt;";
    foreach($matches3 as $match) {
        $list3 .= "&lt;li&gt;&lt;div class='int'&gt;".implode("&lt;/div&gt;&lt;/li&gt;&lt;li&gt;&lt;div class='int'&gt;", $match)."&lt;/div&gt;&lt;/li&gt;\n";
    }
    $numIe = count($matches3[0]);
    $lis3t .= "&lt;/ol&gt;";
}else{
    $list3 = "No matches found";
}
</code></pre>

<p>any help will really be helpful guys!</p>
