Eckstra Posted July 2, 2006 Share Posted July 2, 2006 Hey everyone.I'm trying to search through an array created by file (), which will have been a website, for example:[code]$lines = file(http://media.putfile.com/Young-Cats-Play-fighting);[/code]so each line of the source code from this page on putfile is stored seperately in the array.The whole idea is for the PHP script to search the source code for the URL to the video file. I would have thought the easiest way would be to use array_search to search the array for wmv, mpg, avi or any other video file extensions, and then go from there. However when I do this the search comes out with no results, possibly because "wmv" or "avi" would only one part of a whole line?Could anyone help me out? Quote Link to comment https://forums.phpfreaks.com/topic/13466-searching-an-array-created-by-file/ Share on other sites More sharing options...
redarrow Posted July 2, 2006 Share Posted July 2, 2006 <?php// Get a file into an array. In this example we'll go through HTTP to get // the HTML source of a URL.$lines = file('http://www.example.com/');// Loop through our array, show HTML source as HTML source; and line numbers too.foreach ($lines as $line_num => $line) { echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) . "<br />\n";}// Another example, let's get a web page into a string. See also file_get_contents().$html = implode('', file('http://www.example.com/'));?> linkhttp://uk.php.net/file Quote Link to comment https://forums.phpfreaks.com/topic/13466-searching-an-array-created-by-file/#findComment-52032 Share on other sites More sharing options...
Eckstra Posted July 2, 2006 Author Share Posted July 2, 2006 Thanks for the reply redarrow. Getting hold of the HTML code isnt a problem, it's getting the script to find the URL to the video file that I cant figure out how to do. Quote Link to comment https://forums.phpfreaks.com/topic/13466-searching-an-array-created-by-file/#findComment-52042 Share on other sites More sharing options...
redarrow Posted July 2, 2006 Share Posted July 2, 2006 the link provides meny solutions with related php code statements. Quote Link to comment https://forums.phpfreaks.com/topic/13466-searching-an-array-created-by-file/#findComment-52043 Share on other sites More sharing options...
Drumminxx Posted July 2, 2006 Share Posted July 2, 2006 try using the stristr function[code]$file = file("path");foreach($file as $line) { if (stristr($line,'.mpg')) { more code to get rid of any unwanted characters }}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/13466-searching-an-array-created-by-file/#findComment-52044 Share on other sites More sharing options...
redarrow Posted July 2, 2006 Share Posted July 2, 2006 http://www.webmasterworld.com/forum88/938.htmexsplode Quote Link to comment https://forums.phpfreaks.com/topic/13466-searching-an-array-created-by-file/#findComment-52048 Share on other sites More sharing options...
.josh Posted July 2, 2006 Share Posted July 2, 2006 not sure if you were looking for all instances of movie type files? also, not sure what part you are actually looking for. the actual movie name? movie name plus extension? entire url? well this code looks for all instances of the movie types defined in $movietypes array and outputs each one in the following format:src="http://url/of/movie/movie.mpg"so you are going to have to tweak the pregmatch a bit if you want something specific within that string. hope this points you in the right direction.[code]<?php //movie types. add to the list for more types $movietypes = array('mpg','wmv','avi'); //file source $lines = file('http://media.putfile.com/Young-Cats-Play-fighting'); foreach ($lines as $codeline) { //foreach line of the filesource foreach ($movietypes as $type) { //foreach type of file //find the needle in the haystack preg_match("|src=\"(.*).".$type."\"|U",$codeline, $out); //if something was found if ($out[0] != '') { //make an array for each item found $found[] = $out[0]; } } } //example of accessing/echoing out the info foreach($found as $val) { echo $val . "<br>"; }?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/13466-searching-an-array-created-by-file/#findComment-52071 Share on other sites More sharing options...
Eckstra Posted July 2, 2006 Author Share Posted July 2, 2006 Thanks Crayon Violent, with a few small changes that worked perfectly. The problem now is forcing the file to be downloaded rather than streamed. I can't change the .htaccess to force files to be downloaded, because they're not being hosted locally, I cant seem to get it to work by playing around with the headers, and I'm not willing to just display the link as text, because it might encourage users to hotlink to the video rather than download it, and I'd like to keep things as simple for the user as possible, some might not understand "right click save target as".Whever I try and change the headers I get the errorWarning: Cannot modify header information - headers already sent by (output started at /home/blah/test5.php:13) in /home/blah/test5.php on line 17Can anyone help? Quote Link to comment https://forums.phpfreaks.com/topic/13466-searching-an-array-created-by-file/#findComment-52225 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.