Forum Moderators: coopster

Message Too Old, No Replies

php code in the php print

trying to print php code

         

weddingm

3:17 am on May 18, 2009 (gmt 0)

10+ Year Member



Hello I am trying to print php code and cannot get it to work. Any suggestions?

print "Ratings:</b> ".$total9."<br> <?php if (".$total9."==0 ¦¦ ".$total9."==NULL) {".$nada."=0;} else {print \"<form method='post' action='https://www.sample.com'><input type='hidden' name='bemail' value='".$webinfo2."'><input type='image' src='images/viewratings.jpg' value='submit' alt='[View Ratings]' width='100'></form>\";} ?> <br>";

Thanks,
Matt

DrDoc

3:28 am on May 18, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



First of all -- single-quote anything you don't want automatically parsed.
Secondly -- echo 'you can always separate' . '?' . '>';
Thirdly -- escape \$characters that might give you trouble, just like you do with \"quotes\"

weddingm

4:48 am on May 18, 2009 (gmt 0)

10+ Year Member



I just took out the php statement and moved it up the ladder. Now it works great.

dreamcatcher

5:46 am on May 19, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Matt,

If you require an if type statement in a string, look into ternary operators.

[uk.php.net...]

dc