php - Get specific line of web page using file_get_contents -


i have file test.txt on 4 lines:

this test 

i have php script when run grabs contents of file , displays me:

<?php $file = file_get_contents('https://www.mywebsite.com/test.txt'); echo $file; ?>

is there way specific line test.txt file?

you explode() new line, like:

$string = file_get_contents('https://www.mywebsite.com/test.txt'); $stringarr = explode("\n", $string); echo $stringarr[2]; //get third line 

or use file() reads entire file array, like:

$lines = file('https://www.mywebsite.com/test.txt'); echo $lines[2]; 

Comments

Popular posts from this blog

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

html - How to custom Bootstrap grid height? -

transpose - Maple isnt executing function but prints function term -