TFD3 Posted December 31, 2007 Share Posted December 31, 2007 I would like to find a script that I can display only certain line of text from a websites source code. Im looking for some script where I can add the URL I want, then add the line number from the source code and have the script only display that line that I chose. Example: Using this URL: and viewing the Source Code and search for LINE 155 LINE 155: var fullscreenUrl = '/watch_fullscreen?video_id=......... BUT...I would like to have a way to cut out ( var fullscreenUrl = '/ ) Is this possible? thanks kenny Link to comment https://forums.phpfreaks.com/topic/83891-displaying-certain-lines-in-websites-source-code/ Share on other sites More sharing options...
hitman6003 Posted December 31, 2007 Share Posted December 31, 2007 the file command will read the page into an array with a numeric key. You can use that to echo out a specific line...just remember that the key will start at 0. http://www.php.net/file $url = "www.google.com"; $line = 10; $web_page = file($url); echo "Line " . $line . " of page " . $url . " is:\n" . $web_page[$line - 1]; Link to comment https://forums.phpfreaks.com/topic/83891-displaying-certain-lines-in-websites-source-code/#findComment-426934 Share on other sites More sharing options...
TFD3 Posted December 31, 2007 Author Share Posted December 31, 2007 I added info to my first post. I cant get your example to work, I have tried this with several sites with no luck. Link to comment https://forums.phpfreaks.com/topic/83891-displaying-certain-lines-in-websites-source-code/#findComment-426947 Share on other sites More sharing options...
sasa Posted December 31, 2007 Share Posted December 31, 2007 i try $url = "http://youtube.com/watch?v=AhO5Pkm3k_8"; $web_page = file_get_contents($url); preg_match("/var fullscreenUrl = '\/([^']+)/",$web_page,$a); print_r($a); it putput is Array ( [0] => var fullscreenUrl = '/watch_fullscreen?video_id=AhO5Pkm3k_8&l=9&t=OEgsToPDskLLZcUW8ZuGr37z_i-zsMBf&sk=Me5nFbc9_C4gD2CLqrGoGAC&fs=1&title=Boxer beats up frisbee [1] => watch_fullscreen?video_id=AhO5Pkm3k_8&l=9&t=OEgsToPDskLLZcUW8ZuGr37z_i-zsMBf&sk=Me5nFbc9_C4gD2CLqrGoGAC&fs=1&title=Boxer beats up frisbee ) Link to comment https://forums.phpfreaks.com/topic/83891-displaying-certain-lines-in-websites-source-code/#findComment-426984 Share on other sites More sharing options...
TFD3 Posted December 31, 2007 Author Share Posted December 31, 2007 i try $url = "http://youtube.com/watch?v=AhO5Pkm3k_8"; $web_page = file_get_contents($url); preg_match("/var fullscreenUrl = '\/([^']+)/",$web_page,$a); print_r($a); it putput is Array ( [0] => var fullscreenUrl = '/watch_fullscreen?video_id=AhO5Pkm3k_8&l=9&t=OEgsToPDskLLZcUW8ZuGr37z_i-zsMBf&sk=Me5nFbc9_C4gD2CLqrGoGAC&fs=1&title=Boxer beats up frisbee [1] => watch_fullscreen?video_id=AhO5Pkm3k_8&l=9&t=OEgsToPDskLLZcUW8ZuGr37z_i-zsMBf&sk=Me5nFbc9_C4gD2CLqrGoGAC&fs=1&title=Boxer beats up frisbee ) Strange.... I tried that same code and I got a blank page: http://www.alabamaweather.org/psp/youtube/test.php Link to comment https://forums.phpfreaks.com/topic/83891-displaying-certain-lines-in-websites-source-code/#findComment-426988 Share on other sites More sharing options...
sasa Posted December 31, 2007 Share Posted December 31, 2007 in source of your link i see <php $url = "http://youtube.com/watch?v=AhO5Pkm3k_8"; $web_page = file_get_contents($url); preg_match("/var fullscreenUrl = '\/([^']+)/",$web_page,$a); print_r($a); ?> <BR><BR><BR> <pre>w OR <br /> <b>Warning</b>: Invalid argument supplied for foreach() in <b>/home2/alabamaw/public_html/psp/youtube/test.php</b> on line <b>27</b><br /> OR w OR <br /> <b>Warning</b>: implode() [<a href='function.implode'>function.implode</a>]: Invalid arguments passed in <b>/home2/alabamaw/public_html/psp/youtube/test.php</b> on line <b>41</b><br /> source code of script it is because PHP does not pharse it what the rest of script does? Link to comment https://forums.phpfreaks.com/topic/83891-displaying-certain-lines-in-websites-source-code/#findComment-426995 Share on other sites More sharing options...
TFD3 Posted December 31, 2007 Author Share Posted December 31, 2007 I forgot to have this added. the first two words of the outputted URL is watch_fullscreen. I need that replaced with get_video can that be added to the script below? I already had this script partly working before I got on here and just played with it to get it to work but I forgot about the replace watch_fullscreen to get_video. <a href="http://www.youtube.com/<?php $html = implode('', file("http://youtube.com/watch?v=bcr6IBnuVHQ")); preg_match_all("/var fullscreenUrl = '\/([^']+)/", $html, $headers); $count = count($headers[1]); for ($x = 0; $x <= $count-1; $x++) { echo $headers[1][$x]."\n"; } ?>">Get Video</a> Link to comment https://forums.phpfreaks.com/topic/83891-displaying-certain-lines-in-websites-source-code/#findComment-427002 Share on other sites More sharing options...
sasa Posted December 31, 2007 Share Posted December 31, 2007 try <a href="http://www.youtube.com/get_video<?php $html = implode('', file("http://youtube.com/watch?v=bcr6IBnuVHQ")); preg_match_all("/var fullscreenUrl = '\/watch_fullscreen([^']+)/", $html, $headers); echo $headers[1]."\n"; } ?>">Get Video</a> Link to comment https://forums.phpfreaks.com/topic/83891-displaying-certain-lines-in-websites-source-code/#findComment-427008 Share on other sites More sharing options...
TFD3 Posted December 31, 2007 Author Share Posted December 31, 2007 try <a href="http://www.youtube.com/get_video<?php $html = implode('', file("http://youtube.com/watch?v=bcr6IBnuVHQ")); preg_match_all("/var fullscreenUrl = '\/watch_fullscreen([^']+)/", $html, $headers); echo $headers[1]."\n"; } ?>">Get Video</a> That worked, thanks for your help!! Link to comment https://forums.phpfreaks.com/topic/83891-displaying-certain-lines-in-websites-source-code/#findComment-427011 Share on other sites More sharing options...
TFD3 Posted January 1, 2008 Author Share Posted January 1, 2008 try <a href="http://www.youtube.com/get_video<?php $html = implode('', file("http://youtube.com/watch?v=bcr6IBnuVHQ")); preg_match_all("/var fullscreenUrl = '\/watch_fullscreen([^']+)/", $html, $headers); echo $headers[1]."\n"; } ?>">Get Video</a> Using the preg_match_all line in the script above, can it be changed to display only sqMv7mjebvk from the line: var pageVideoId = 'sqMv7mjebvk'; from the source code of the youtube video link?? Thanks guys for your help! Link to comment https://forums.phpfreaks.com/topic/83891-displaying-certain-lines-in-websites-source-code/#findComment-427295 Share on other sites More sharing options...
sasa Posted January 1, 2008 Share Posted January 1, 2008 preg_match_all("/var pageVideoId = '([^']+)/", $html, $headers); Link to comment https://forums.phpfreaks.com/topic/83891-displaying-certain-lines-in-websites-source-code/#findComment-427389 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.