evank3 Posted February 21, 2007 Share Posted February 21, 2007 Is it possible to just read a certain line of a file and put it into the output? If it took out html codes that would be nice, but it doesn't need to. all I need to do is read a certain line of a external site like www.example.com Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted February 21, 2007 Share Posted February 21, 2007 the link you gave was a faulty one, if you just want to read one line of a text file: $contents = file("text.txt"); echo $contents[0];//this would give you line one echo $contents[4];//this would give you line five echo $contents[99];//this would give you line one hundred echo "and so on";//ignore this Is this what you are looking for? Ted Quote Link to comment Share on other sites More sharing options...
evank3 Posted February 21, 2007 Author Share Posted February 21, 2007 Well sort of, but I meant to read an external file from another website. like when you do view source on a page but only grabbing a certain line Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted February 21, 2007 Share Posted February 21, 2007 I dont think include and require can get the contents of foreign pages, but I think file_get_contents() might work. Ted Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted February 21, 2007 Share Posted February 21, 2007 I cant find any related articles in google, please try and tell me the results. Ted Quote Link to comment Share on other sites More sharing options...
evank3 Posted February 21, 2007 Author Share Posted February 21, 2007 Its almost working perfectly! the only problem is that its reading the characters in the file not lines. like the code you gave me gave me the first, fifth, and ninty-ninth character in the file instead of giving me certain lines. Here is my code: <php file_get_contents("URL OF WEBPAGE"); echo $contents[0];//this would give you line one echo "<br>"; echo $contents[4];//this would give you line five echo "<br>"; echo $contents[99];//this would give you line one hundred ?> Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 21, 2007 Share Posted February 21, 2007 http://us3.php.net/file_get_contents "Identical to file(), except that file_get_contents() returns the file in a string," Quote Link to comment Share on other sites More sharing options...
tom100 Posted February 21, 2007 Share Posted February 21, 2007 explode the string using \n. Strings, when used like an array return the character at that position. So $content=file_get_contents($url); $lines=explode("\n", $content); $lines[0] //Line 1 etc Quote Link to comment Share on other sites More sharing options...
evank3 Posted February 21, 2007 Author Share Posted February 21, 2007 Thank you so much everyone! Quote Link to comment 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.