-1

I have come across a seemingly straightforward issue which I cannot find the answer for anywhere.

For some reason the PHP tags I’m using don’t seem to be working. I am opening with <?php and closing with ?>, but for some reason the closing tag is not being recognised as code and is showing up when I refresh the browser:

<?php  
echo <p>Data Processed</p>;
?>

shows in the browser as

Data Processed

;?>

I must be missing something really simple.

Sebastian Simon
  • 16,564
  • 7
  • 51
  • 69

1 Answers1

0

You need to quote your strings. You code is just outputting everything till it get to the end of the command. Thus to the end of the file.

<?php  
echo '<p>Data Processed</p>';
?>
Jason K
  • 1,386
  • 1
  • 9
  • 15
  • thanks for the quick response mate, ive done exactly as you have suggested and the only difference it has made to the output is it has added the quotaions before the closing tag Data Processed '; ?> – Luke Jackson Jul 25 '16 at 20:38
  • Do you have teamviewer so i can perhaps show you the problem? – Luke Jackson Jul 25 '16 at 20:39
  • Do a view source on the page. If you see your php code. The php parser is not running and web browser is just parsing the code as html. – Jason K Jul 25 '16 at 20:45
  • @LukeJackson What happens when you ` echo '

    Data Processed

    '; ?>` instead?
    – Aaron Jul 25 '16 at 20:45
  • Jason i think this may be the issue, how can i go about getting my parser to run? – Luke Jackson Jul 25 '16 at 20:50
  • Aaron the only difference when i add quotations is that the closing quotation also shows in the browser before the closing tag – Luke Jackson Jul 25 '16 at 20:51
  • @LukeJackson What's is your filename? Does it end with `.php`? – Aaron Jul 25 '16 at 20:51
  • @Aaron you have it. I was over thinking it. Luke your php parser is not running. Make sure your file name ends in .php – Jason K Jul 25 '16 at 20:52
  • The filename definitely ends in .php - does that mean the parser should be running already?:/ – Luke Jackson Jul 25 '16 at 20:55
  • @LukeJackson How are you viewing the php file? Is it uploaded on a server? More easily put, What is the URL? – Aaron Jul 25 '16 at 20:57
  • Im intending to use a local xampp server to host it for now. Im not sure if ive done this right as ive just saved the file within xampps htdocs : file:///C:/xampp/htdocs/phptutorial/learnphp.php – Luke Jackson Jul 25 '16 at 21:00
  • @LukeJackson Yes but what is the URL on the browser? Is it along the lines of `file:///C:/xampp/htdocs/phptutorial/learnphp.php` – Aaron Jul 25 '16 at 21:01
  • @LukeJackson You need to access the file through a web-server/local-server, not through the directory. That's why it's not going through the php parser. The URL to access your `learnphp.php` should be around your localhost or `127.0.0.1` – Aaron Jul 25 '16 at 21:03
  • right, so should i be viewing it through my localhost?(xampp) if so what would the url be? – Luke Jackson Jul 25 '16 at 21:05
  • @LukeJackson That's for you to figure out but theoretically if the file was placed on the home directory, it would be something like `127.0.0.1/learnphp.php` – Aaron Jul 25 '16 at 21:05
  • hmm do you have teamveiwer to have a look at it mate? im trying 127.0.0.1/ all the different locations but its giving me nothing – Luke Jackson Jul 25 '16 at 21:09
  • @LukeJackson Well we found the source of the problem and the solution. My part is done here. – Aaron Jul 25 '16 at 21:13
  • My guess would be 127.0.0.1/phptutorial/learnphp.php – Jason K Jul 25 '16 at 21:14
  • Thanks mate your the boss – Luke Jackson Jul 25 '16 at 21:15
  • It isnt working in any combination i try im afraid, thanks for both your help i can probably try and diagnose this next step myself now:) – Luke Jackson Jul 25 '16 at 21:17