Page 1 of 1
PHP stops handling my page every time it encounters >
Posted: Fri Nov 24, 2006 5:25 pm
by BeauMN
Hi,
I'm new to PHP, but not to programming. I have installed the latest Apache server and the latest PHP as an Apache module. It works fine, but evertime there is a greater-than (>) symbol in my PHP code, PHP stops handling the code. I don't know why this is. I was under the impression that the > must be preceded by ? for this to happen. I need to use > in my PHP code so that I can have html tags in my calls to the echo() function.
Thanks,
Beau
Posted: Fri Nov 24, 2006 5:40 pm
by wtf
post some code
Posted: Fri Nov 24, 2006 5:51 pm
by BeauMN
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Code: Select all
<?php
class Calendar
{
private $month=array();
private $current=array();
function __construct()
{
$month["name"] = "November"; $month["number"] = 30;
}
function Display()
{
echo '<table>'; //from here on everything after the > insn't executed by PHP
echo '<tr>';
for($i=0; $i<$month["number"]; i++)
{
echo '<td>';
echo "<h2>$i</h2>";
echo '</td>';
}
echo '</tr>';
echo '</table>';
}
}
$c = new Calendar();
$c->Display();
?>
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Posted: Fri Nov 24, 2006 6:35 pm
by John Cartwright
This has nothing to do with that operator, instead you have undefined variables, your loop isn't evaluating because $i will always be greater than nothing.
You would have been aware of this if you had error_reporting(E_ALL); set
Instead, you need to reference your class variables
Code: Select all
function __construct()
{
$month["name"] = "November"; $month["number"] = 30;
}
These variables will only be accessible within that method. Try
Code: Select all
function __construct()
{
$this->month["name"] = "November";
$this->month["number"] = 30;
}
To bring the variables into class scope.. and obviously change the other instances of those variables accordingly.
Posted: Fri Nov 24, 2006 6:44 pm
by m3mn0n
Moved to PHP Code.
Posted: Fri Nov 24, 2006 6:59 pm
by BeauMN
Hmm, I just tried that, and now PHP stopped executing after the > in $this->
I'm pretty sure that it is the > operator that is messing things up for me. I tried the following code as a test:
Code: Select all
<?php
echo "<p>Hello</p>";
echo "<p>World</p>";
?>
When I do this, the output in my browser is the following:
Hello"; echo "
World
"; ?>
As you can see, PHP stops executing after the > operator, wherever it is found in the PHP code. I'm figuring this might be a problem with my server configuration, but have no clue how to fix it. I left the default install options for Apache and PHP, using the recommended php.ini file. The only changes I made to the default Apache configuration were to load PHP as a module.
Any ideas?
Posted: Fri Nov 24, 2006 7:05 pm
by nickvd
Assuming that the simple hello world script is in-fact causing the problems, I would suspect a corrupted php installation... re-install php and the problem will probably go away...
as an aside, what version of php are you running (show us the top part of the phpinfo() output)
Posted: Fri Nov 24, 2006 7:39 pm
by BeauMN
Haha, okay, it was all my mistake from the beginning. I forgot to change the extensions on my pages to .php
They had been .html files
Sorry
Posted: Sun Nov 26, 2006 6:40 pm
by John Cartwright
BeauMN wrote:Haha, okay, it was all my mistake from the beginning. I forgot to change the extensions on my pages to .php
They had been .html files
Sorry
Happens to us all, take care.