Welcome to WebmasterWorld Guest from 50.19.156.133

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Adding <H2> to PHP Echo function

     

Kangol

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

10+ Year Member



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.

mcibor

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

WebmasterWorld Senior Member 10+ Year Member



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

Kangol

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

10+ Year Member



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

Topic Title<h2></h2>

mcibor

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

WebmasterWorld Senior Member 10+ Year Member



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

Kangol

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

10+ Year Member



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.

Kangol

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

10+ Year Member



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.

mcibor

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

WebmasterWorld Senior Member 10+ Year Member



Will work

Regards
Michal

 

Featured Threads

Hot Threads This Week

Hot Threads This Month