1

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?

3
  • <--?PHP echo "test"; --> whats this? it should be <?php echo "test";?> Commented Jan 17, 2014 at 7:10
  • <?PHP echo "test"; ?> Commented Jan 17, 2014 at 7:11
  • yes I know the above is what Google developer tools show me when I inspect the code. I know it should be <?php echo"test" ?> Commented Jan 17, 2014 at 7:12

4 Answers 4

2

The correct one should be like this,

<?php echo "test";?>

Also, make sure that your page is saved with .php extension, not .html

Sign up to request clarification or add additional context in comments.

3 Comments

my page is saved with .php extension yes I know it should be <?php echo"test";?> Google developer tools show me <--?PHP echo "test"; --> when I inspect the code
@user2955598 because PHP is server side scripting, where as javascript is client side. you can't see the PHP scripts on inspection instead you can see only html markups, but you can see the javascript on inspection
But what can I do so that my code gets echoed something simple lik <?PHP echo"Hello World" ?> is not working....and nothing gets displayed
1

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).

Comments

0

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.

Comments

0

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:

  1. 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.

  2. 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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.