[SOLVED] - Inserting direct HTML in functions

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

[SOLVED] - Inserting direct HTML in functions

Post by anjanesh »

Do these really make a difference ?

Code: Select all

<?php
function Display1()
{
  ?>
  Hello<BR>
  <?
}
function Display2()
{
  ?>
  Hello<BR>
  <?php
}
function Display3()
{
  echo 'Hello<BR>';
}
?>
All 3 displays work on my machine but in the server Display2 doesn't show up. Gives some error and after removing php from the <?php it showed up alright.
I know this is a function and I wanted to know if direct insertion of HTML tags will do any harm when compared to echo ?
Thanks
Last edited by anjanesh on Tue Aug 10, 2004 11:11 pm, edited 1 time in total.
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

If I remember correctly, you can't exit php while in a function declaration. Although it may just apply to classes.. I believe it's both.

display3 is the correct way to go about doing it.
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

All 3 may work but LilpunkSkateR is corre t use display3. The other two will only cause you problems.
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

Alright. I'll use echo for all the lines.
But then again

Code: Select all

echo 'Text $row["id"] Text'; is not working
echo "ext $row['id']  Text"; while this is
Are ' and " treated differently ?
Last edited by anjanesh on Tue Aug 10, 2004 10:48 pm, edited 1 time in total.
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

Yes, and please use PHP tags. '' does not look for variables in a string where " " does.
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

I changed all that because I was getting this error and it still shows up:
Parse error: parse error, unexpected $end in xxxxxxx\xxx.php on line 211

There is a ?> at end. Now only one because the first one was for <?php at the location of function defiition. I knew I had many of <? and ?> and so I converted them all the echo but the error still shows ! There are only 210 lines and errno is 211 !!!
Last edited by anjanesh on Tue Aug 10, 2004 10:52 pm, edited 1 time in total.
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

Post t your code in PHP tags and we'll take a look at it. Your error typically means you are trying to access a variable where variables don't belong.
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

The entire code is 200 lines. How can I show you the ones required. I jist moved the function to another file so now its a lot lesser but still...
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

Guess its the function thats giving the error. Now its showing that filename - the one where I moved the fn to

SOLVED - stupid mistake
Post Reply