String searcher function

I have had some trouble with this code. I can’t get this function to work. It keeps saying there is an unexpected T_VARIABLE. I can’t find the syntax error or the problem. Any help would be great.

<?php //takes a file $source and searches for $start and $ending and returns the middle. function getMiddle($source, $start) { $fh = fopen($source, 'r') or die("can't open file"); $theData = fread($fh, filesize($source)); $beginning=$start; $ending="# #\n"; $bPos = strpos($theData, $beginning); $mPos = $bPos + strlen($beginning); //the error shows up for this line. $ePos = strpos($theData, $ending, $bPos + 1); $middle = substr($theData, $mPos, $ePos - $mPos); fclose($fh); return $middle; } ?>

There is no syntax error in that code. Maybe that line number in a different file?

I know its not another file. I have no references to any other file, except for the file I am searching. The error that pops up everytime is “Parse error: syntax error, unexpected T_VARIABLE in [my document location on server] on line 15” which is the line after the line I marked. I don’t know why the server I use (000webhost.com) is causing that error. Any ideas as to what I can do to check where that error is coming from? Thanks.

I think I figured it out, there was a space after the semicolon. It went away after I deleted it.

Sponsor our Newsletter | Privacy Policy | Terms of Service