0

I am trying to create a page that when someone types a specific movie in the search bar it goes to a page on my server with an embedded vlc player and plays that movie. I tried by storing the userinput as a variable in an array using php but i either get one of two errors array to string conversion or undefined index!

I'm using pregmatch to scan a txt file containing my movies and want it to take the file name that most matches the user input and add it to the src = $variable of my embeded player so i nly have to have one page to play 100 or more movies.

heres the php source and the embeded video player html

html video embed : ' /> and the source code for pregmatch!

<div class="search" align = "center">
<form action="MovieMatch.php" method ="post">
<input type="text" name="userget"  />
<input type="submit"name="submit" value="<?php$pick ?>" />

</form>
</div>
<h1 align = "center" class="text-primary">Search our Movies!</h1>
<div class="images" >


<?php
ini_set('display_errors', 'On');
error_reporting(E_ALL);

if(isset($_POST['submit'])){
$submit = $_POST ["userget"];//storing input



$file = 'movielist.txt';




// get the file contents, assuming the file to be readable (and exist)
$contents = file_get_contents($file);
// escape special characters in the query
$pattern = $submit;
// finalise the regular expression, matching the whole line
$pattern = "/^.*$pattern.*\$/m";

$handle = fopen("movielist.txt", "r");




// search, and store all matching occurences in $matches
if(preg_match_all($pattern, $contents, $matches)){

$pick = implode("\n", $matches[0]); 

echo $pick[1];

   echo "Found matches:\n";




 echo '<a href="http://127.0.0.1/alphastream/categories/'.$pick. '" class = "button">click me!</a>'; // this is my fix bu

}

else{
   echo "No matches ";


        }
    } 

?>

  • Second time today I've seen someone do `$pattern = preg_quote($submit, '/');` What's that from and why are you doing it? – Keith Tyler Mar 25 '16 at 21:14
  • absolutely nothing for me changed it to $pattern = $submit; but it would add the backslashes/// – nate andreano Mar 25 '16 at 22:41
  • @KeithTyler I couldn't find an exact match for `pattern = preg_quote($submit, '/');` but searching for the comments in OP's code shows that this snippet has been thrown around and copy/pasted for at least 5 years. [Here's one](https://stackoverflow.com/questions/10116588/preg-match-to-get-mp3-and-mp4-filenames-in-file-extension-order-then-in-filename), [here's another](https://stackoverflow.com/questions/7118497/display-in-the-table-if-search-matches-in-php) and [another](https://stackoverflow.com/questions/3686177/php-to-search-within-txt-file-and-echo-the-whole-line) – jDo Mar 25 '16 at 23:17
  • Absolutely right i copied and edited the pregmatch code from a couple different sites so my app would work like i wanted it the above source works if you add the movie in the list.txt but only if you make a webpage for each movie and add the movie.php into the list – nate andreano Mar 25 '16 at 23:24
  • i want to play all movies that a user picks on one page using pregmatch to compare user input to the list.txt and finding the movie.ext storing it into a variable then adding it to the embedded video src rather then using a href to point to individual pages – nate andreano Mar 25 '16 at 23:30
  • There is no point in `$handle = fopen("movielist.txt", "r");`; you are already reading the file with file_get_contents(). Although probably actually want file() which will retrieve an array of lines from the file. Then you would foreach over the result of $file, applying preg_match to it. So... hold on... you have a file called movielist.txt -- this contains JUST movie names? Then how do you link the movie names to their actual movie files? – Keith Tyler Mar 28 '16 at 22:33
  • Thank you for your advice i store the php filename in movie list then point to that dir with the movie embedded in the php using vlc. example daddys home.php – nate andreano Mar 29 '16 at 18:34
  • thats my problem i have to write 100 pages to play 100 different movies.. one page for 100 movies would be better but i think the way i retrieve the movie name from the array retirns illegal array to string conversion thats my problem user input picks the closest matching movie in the list and stores it as a variable them i place that variable into the embedded video src=$pick using php embed tags – nate andreano Mar 29 '16 at 18:38

0 Answers0