Why my php code is commented ?

ocsidot

New Member
Messages
1
Reaction score
0
Points
0
Hi everybody,

First of all, sorry if my question was already answered somewhere, but I can't find out how to resolve my problem :(.

So, I'm a beginner in PHP programmation and for my studies, I have to write a page which read information from an other address and display it.

Code:
<?php
$adresse = "[URL]http://www.casablanca-technopark.ma/detail_ese.asp?ID=56[/URL]"; 
$page = @file_get_contents ($adresse);
 echo "$page <br>";
?>

But when I open my page, I see nothing and when I look at the source code, I see that my php code is commented.

So, could anyone please tell me what I've missed ?

Thank you very much for all the help you can provide me.

ps: Sorry for my english, I'm french ;)
 

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
If the page name is index.html , the PHP is never executed. It has to be index.php
 

callumacrae

not alex mac
Community Support
Messages
5,257
Reaction score
97
Points
48
Code:
<?php
$adresse = "[URL]http://www.casablanca-technopark.ma/detail_ese.asp?ID=56[/URL]"; 
$page = @file_get_contents ($adresse);
 echo "$page <br>";
?>

Try removing the @. If there is any error there, it will be suppressed and the page will load blank.
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
But when I open my page, I see nothing and when I look at the source code, I see that my php code is commented.
"Commented" is completely the wrong term; commented code would be surrounded by "/*" and "*/", or have "//" at the beginning of each line (for PHP comments), or be surrounded by "<!--" and "-->' (for HTML comments). What you probably mean is that when you view the source of the page in a web browser (where you view it is an important detail), you see the PHP code, which indicates the PHP wasn't executed by the web server.

And contact the echo page like
Code:
echo $page."<br>";
There's no practical difference between using the concatenation operator and string interpolation. Simpler than file_get_contents and echo would be to use readfile.

Lastly, <br/> is rarely used semantically, and completely unnecessary here. Normally, I'd say to use something more appropriate, such as a paragraph or list element, or apply styling to existing elements, but here, leave it out entirely.
 
Last edited:
Top