- how can i make my php code shorter?
- $_ = NULL;
- $msg = "<br />[ Your Script ".$handle->file_dst_name_body." has been uploaded ]<br />";
- $file = $handle->file_dst_path.$handle->file_dst_name_body.'.'.$handle->file_dst_name_ext;
- $open = fopen($file, 'r+');
- $story = utf8_decode(fread($open, filesize($file)));
- echo $msg.'<br />';
- $sf = new TextFileReader($file);
- $sf->seekLine(1); // Go to line 1
- echo "Total number of lines: ".$sf->countLines()."<br />";
- if(preg_match_all('/s{68}(.*)/m', $story, $_))
- {
- $unique_pages = array_unique(array_map(create_function('$a', 'return ucfirst(strtolower(trim($a)));'), $_[1]));
- echo "<span><strong>Pages: </strong>".count($unique_pages)."</span><br />";
- }
- $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 = "<ol>";
- foreach($matches as $match) {
- $list .= "<li><div class='int'>".implode("</div></li><li><div class='int'>", $match)."</div></li>n";
- }
- $numInt = count($matches[0]);
- $list .= "</ol>";
- }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 = "<ol>";
- foreach($matches2 as $match) {
- $list2 .= "<li><div class='int'>".implode("</div></li><li><div class='int'>", $match)."</div></li>";
- }
- $numExt = count($matches2[0]);
- $list2 .= "</ol>";
- }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 = "<ol>";
- foreach($matches3 as $match) {
- $list3 .= "<li><div class='int'>".implode("</div></li><li><div class='int'>", $match)."</div></li>n";
- }
- $numIe = count($matches3[0]);
- $lis3t .= "</ol>";
- }else{
- $list3 = "No matches found";
- }
- // search, and store all matching occurences in $matches
- if (preg_match_all($pattern2, $contents, $matches2)) {
- $list2 = "<ol>";
- foreach($matches2 as $match) {
- $list2 .= "<li><div class='int'>".implode("</div></li><li><div class='int'>", $match)."</div></li>";
- }
- $numExt = count($matches2[0]);
- $list2 .= "</ol>";
- }
- else {
- $list2 = "No matches found";
- }