saer Posted December 10, 2010 Share Posted December 10, 2010 Heya I'm having some problem with my code, take a look: static function ripDictionary($dictPath, $regexPattern, $numKeyWordsToAquire){ $file = fopen($dictPath, "r") or exit("Failed to open the dictionary"); echo $regexPattern ."<br>"; echo $numKeyWordsToAquire ."<br>"; while(!feof($file)){ $line = fgets($file); if(preg_match($regexPattern, $line, $matches)){ for($i=1; $i<=$numKeyWordsToAquire; $i++){ echo $matches[$i] . " "; } echo "<br/>"; } else{ echo "No match<br>"; } } fclose($file); } Ok, so when I run this nothing is returned, I just scroll down to see a tonne of blankness. I think the problem has got something to do with me passing preg_match the $regexPattern variable, because if I add in the line: $regexPattern = "/(.*) (.*) \\[(.*)\\] (.*)/"; before the while loop it works just fine. Can anybody help me out, this is really annoying me. Could it be to do with the fact that the $regexPattern variable is being passed to this static function from a completely different class and .php file or that the regexPattern is coming from post data? This is the HTML file I am using to submit the form too, just incase there are any abnormalities there take a look: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> </head> <body> <form action="uploadDict.php" method="post" enctype="multipart/form-data"> <label for="file">Filename: </label> <br /> <input type="file" name="file" id="file" /> <br /> <label for="regexPattern">Regex Pattern: </label> <input type="text" name="regexPattern" id="regexPattern"> <br/> <label for="numKeyword">Number of keywords to aquire: </label> <input type="text" name="numKeyword" id="numKeyword"> <br/> <input type="submit" name="submit" value="submit" /> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/221199-preg_match-wont-accept-a-variable-as-a-parameter/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.