Jump to content

Weird premature script termination


PositronicSpleen

Recommended Posts

I'm sort of new at PHP, but I've been having a really simple, really strange problem. Whenever I try to print HTML tags through PHP, the greater-than symbol (>) always terminates the script early. The problem isn't exactly the same on IE as Firefox, but they're both problematic. Furthermore, I've tried this on XP, Vista, and Windows 7, on separate machines. All signs point to me having done something wrong, but I honestly can't figure out what's going on; I even tried using example code, but that doesn't work either! I took a screenshot of the script and how it renders in two browsers, it's the attachment.

 

[attachment deleted by admin]

Link to comment
Share on other sites

Try writing this script in NOTEPAD, and run it again:

<?php
echo '<h1>HTML tags hate me</h1>';
?>
<h1>HTML tags hate me</h1>

 

I'm not sure if your code editor converts the < to < or otherwise but it shouldn't perform as so.

 

EDIT: PHP is serverside, it shouldn't matter which browser it's on. Firefox usually hides PHP tags. It might be the problem I thought. In IE+FF, What does the source code say when you view it? Is part of the PHP code there?

Link to comment
Share on other sites

Do you have a php server? like apache? You can't just run PHP in a browser like javascript/html.

 

You're right! I did not notice him running it off a folder, especially .html.

 

OP, download something such as WAMP to run PHP code. Once installed you can access your pages from http://127.0.0.1/index.php provided your php files are in C:\easywamp\www\index.php or similar.

 

A good thing about WAMP is it includes Apache linked to PHP/SQL so you do not need to endlessly configure it to run on your machine. This is a simple way to test PHP files which are compatible when you upload them online.

Link to comment
Share on other sites

I was running it from a server before, I just changed machines and thought this would be faster. The result on a live server is exactly the same, as evidenced by another attached screenshot.

 

Actually, you can see the URL now, I guess it's no big deal. Does anyone else get the same result?

 

[attachment deleted by admin]

Link to comment
Share on other sites

I was running it from a server before, I just changed machines and thought this would be faster. The result on a live server is exactly the same, as evidenced by another attached screenshot.

 

Actually, you can see the URL now, I guess it's no big deal. Does anyone else get the same result?

 

You're entering the PHP code into a .html document, therefor the server will NOT parse it as PHP and give you that erroneous code.

 

You will need to add the following to your .htaccess file to run PHP code within html:

AddHandler application/x-httpd-php .php .html

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.