LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-29-2009, 02:45 PM   #1
beebopbogo
Member
 
Registered: Oct 2006
Posts: 38

Rep: Reputation: 15
How do I print lots of html code within a PHP if statement


I am writing an index.php file and have hit a wall. I would like to print a section of html code, but only if there is content available from the input files. If I put a print() statement before every line of html code it would work, but it would look horrible (with all the escape characters and all. Anyone have any ideas?

Rough example:
<?php
if(something==true)
{
<div>
<div>
...
<img src="file.jpg">
... etc etc ...
</div>
}
else
do nothing



I don't want to replace 100 lines like this:
<img src="file.jpg">

with this:

print("<img src=\"file.jpg\">");
 
Old 08-29-2009, 02:55 PM   #2
beebopbogo
Member
 
Registered: Oct 2006
Posts: 38

Original Poster
Rep: Reputation: 15
Argh: a simple look at the PHP documentation fixed that issue!

if(blah)
{
print <<<END
<div>
...
</div>
END;
}
 
Old 08-29-2009, 07:27 PM   #3
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
It is easier:

PHP Code:
<?php
if ($foo == 1) {
  
?>
  <div> 
  <div>
  ...
  <img src="file.jpg">
  ... etc etc ...
  </div>
  <?php
} else {
  
?>
  <img src="file.jpg">
  <?php
}?>
jlinkels
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Error in Perl Code : Bad switch statement(Problem in code block)? near ## line # suyog255 Programming 4 02-20-2008 05:35 PM
validity of html code in php scripts rblampain Programming 4 01-21-2006 09:24 AM
php in html code blizunt7 Programming 5 06-15-2005 01:08 PM
Control print output from PHP/HTML... PDF? alar Linux - General 1 08-05-2004 01:20 AM
Set up Apache to read php IN html code? WorldBuilder Linux - Networking 10 01-27-2004 12:16 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:21 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration