phpil Posted March 23, 2013 Share Posted March 23, 2013 I'm pretty new to php, not so new to programming. My problem is really simple, and seems almost impossible to search for. When I reference an html link, the // renders everything after http: as a comment. I'm trying to learn to write webbots. This is the first basic lesson of the book "Webbots, Spiders and Screenscrapers": $target = "http://www.example.com/index.html"; $file_handle = fopen($target, "r"); while(!feof($file_handle)) echo fgets($file_handle, 4096); fclose($file_handle); It fails on both my Linux machine and Mac. "Parse error: parse error in Command line code on line 1". In the editor (nano) I see that everything after http: in line 1 is highlighted as a comment. This is straight from the book. What am I doing wrong? Link to comment https://forums.phpfreaks.com/topic/276044-turns-link-into-comment/ Share on other sites More sharing options...
phpil Posted March 23, 2013 Author Share Posted March 23, 2013 So far I've tried escaping, cat'ing, putting it into single quotes. http:\/\/www.example.com doesn't work either. Link to comment https://forums.phpfreaks.com/topic/276044-turns-link-into-comment/#findComment-1420442 Share on other sites More sharing options...
davidannis Posted March 23, 2013 Share Posted March 23, 2013 works for me as posted. Do you have <?php at the top and ?> at the end? Link to comment https://forums.phpfreaks.com/topic/276044-turns-link-into-comment/#findComment-1420498 Share on other sites More sharing options...
haku Posted March 23, 2013 Share Posted March 23, 2013 The first line of the code you've shown is is fine, so you haven't shown us the actual line 1. Show us your actual code, and please wrap it in code tags, which you can do by using the <> button in the editor. Link to comment https://forums.phpfreaks.com/topic/276044-turns-link-into-comment/#findComment-1420522 Share on other sites More sharing options...
phpil Posted March 24, 2013 Author Share Posted March 24, 2013 Sorry about the code tags. This is exactly what I have, edited with nano and run in a terminal on Mac and Linux. <?php $target = 'http://www.example.com/'; $file_handle = fopen($target, "r"); while(!feof($file_handle)) echo fgets($file_handle, 4096); fclose($file_handle); ?> I just added the <?php ?> tags, but still the same error. "Parse error: parse error in Command line code on line 1". I've tried in Mac and Linux, ran it with "php -r" in the command terminal. Link to comment https://forums.phpfreaks.com/topic/276044-turns-link-into-comment/#findComment-1420628 Share on other sites More sharing options...
phpil Posted March 24, 2013 Author Share Posted March 24, 2013 I'm not sure it has anything to do with the // in the html link. I really just need help. Link to comment https://forums.phpfreaks.com/topic/276044-turns-link-into-comment/#findComment-1420635 Share on other sites More sharing options...
haku Posted March 24, 2013 Share Posted March 24, 2013 Line 1 is the opening pho tag. There is nothing wrong with it. Link to comment https://forums.phpfreaks.com/topic/276044-turns-link-into-comment/#findComment-1420645 Share on other sites More sharing options...
davidannis Posted March 24, 2013 Share Posted March 24, 2013 What is the file extension? Should be .php Can you post the entire command used to run the program. Are you sure that you are executing the correct file because if you added a line at the top <?php then the line at which the error occurs should move down one line? Link to comment https://forums.phpfreaks.com/topic/276044-turns-link-into-comment/#findComment-1420739 Share on other sites More sharing options...
kicken Posted March 24, 2013 Share Posted March 24, 2013 I've tried in Mac and Linux, ran it with "php -r" in the command terminal.Don't use php -r to run a file, just do php yourfile.php. The -r flag is for passing code directly as a parameter which can get complicated quickly when you start involving quotes or multiple statements. Only use -r for quick one or two statement bits of code, eg: php -r 'echo dechex(123456);' Link to comment https://forums.phpfreaks.com/topic/276044-turns-link-into-comment/#findComment-1420782 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.