Welcome to WebmasterWorld Guest from 54.156.67.122

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Adding <H2> to PHP Echo function

     
3:04 pm on Feb 27, 2007 (gmt 0)

Junior Member

10+ Year Member

joined:Dec 14, 2004
posts:199
votes: 0


Hi,
I am tryng to add an H2 and css class to an echo function.

<? if ($mpfirstpost==1) echo topic_title();?>

This displays right the title of the post but I want to add an H2 to it. When I do it the page does not loads. I was thinking at

<? if ($mpfirstpost==1) echo <h2>topic_title()</h2>;?>
but its clearly an syntax error.

What is the right code?

Thanx.

3:06 pm on Feb 27, 2007 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Nov 26, 2003
posts:1133
votes: 0


You can echo only strings, so:

<? if ($mpfirstpost==1) echo '<h2>'.topic_title().'</h2>';?>

will work

Remember, that there is difference between
echo "text $variable text";
and
echo 'text $variable text';

Regards
Michal

3:14 pm on Feb 27, 2007 (gmt 0)

Junior Member

10+ Year Member

joined:Dec 14, 2004
posts:199
votes: 0


Thanx for the fast response.
The page does loads but the output is:

Topic Title<h2></h2>

3:23 pm on Feb 27, 2007 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Nov 26, 2003
posts:1133
votes: 0


What do you have in function topic_title(), how do you echo the data there?

Because it's not a normal behavious of the script

I can think only that topic_title() sets some variables, which only then are echoed to page

3:27 pm on Feb 27, 2007 (gmt 0)

Junior Member

10+ Year Member

joined:Dec 14, 2004
posts:199
votes: 0


Yes indeed. There is something going on with the topic_title(). If I replace it with another word it works well.

topic_title() is a function that gets the topic's title from a DB based on the topic's id.

3:33 pm on Feb 27, 2007 (gmt 0)

Junior Member

10+ Year Member

joined:Dec 14, 2004
posts:199
votes: 0


Well,
I've come up with a lame solution:

<h2><? if ($mpfirstpost==1) echo topic_title();?></h2>

Duh... I should of thought of it before.
Thanx for your help.

3:38 pm on Feb 27, 2007 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Nov 26, 2003
posts:1133
votes: 0


Will work

Regards
Michal

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members