Reputation: 1598
This is a very strange problem for me. My page is designed mostly in HTML however when I enter PHP mode and do something simple like this:
echo"Hello World";
Nothing gets printed on the screen. Upon further investigation in developer tools I get the following from the PHP statement I want to echo
<!--?PHP echo "test"; -->
What could be the problem?
Upvotes: 1
Views: 95
Reputation: 146350
I can reproduce your problem if I write this code into a static HTML file:
<?PHP echo "test"; ?>
load the file in Google Chrome and then inspect the HTML with the bundled Developer Tools (I guess that's what you call "Google Development Tools").
The explanation is:
PHP is a server-side language. If your server is configured to execute PHP and you're written valid PHP code in a file that's parsed by the PHP interpreter then the browser will never see the PHP source code. Since you're seeing it, something's wrong in your setup.
Advanced client-side HTML consoles do not show the raw HTML. Instead, they draw a nice tree graph with the result of parsing the HTML source code into memory. As such, invalid HTML tags have long been fixed or removed. In your case, Chrome decides to fix <?php ... ?>
(which is valid PHP but not HTML) by converting it into an HTML comment tag. You have to hit Ctrl+U
(View Source) to see the actual HTML sent by server.
Upvotes: 0
Reputation: 50190
Sounds like you're trying to embed PHP in a page managed by a framework. If this is the case, the framework is evidently rewriting your html and quarantining your PHP in a comment. (E.g., this might happen in a WordPress page or something else that "cleans" its HTML content).
Upvotes: 1
Reputation: 593
Another way to do it is by using short open tags:
<?="test"?>
This is only working if short_open_tags
is enabled in php.ini
- or if you're using PHP 5.4.0 or greater.
Upvotes: 0
Reputation: 10555
The correct one should be like this,
<?php echo "test";?>
Also, make sure that your page is saved with .php
extension, not .html
Upvotes: 2