Jump to content

// turns link into comment


phpil

Recommended Posts

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

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.

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?

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);'

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.