Enjoy an ad free experience by logging in. Not a member yet?
Register .
01-09-2011, 07:24 PM
PM User |
#1
New Coder
Join Date: Jan 2011
Location: United States
Posts: 24
Thanks: 4
Thanked 0 Times in 0 Posts
Embeding PDF in HTML under a PHP if command
PHP Code:
<?php
$listmonth =array( "January" , "February" , "March" , "April" , "May" , "June" , "August" , "September" , "October" , "November" , "December" );
foreach ( $listmonth as $month ) {
if ( file_exists ( $year2 . '-' . $month . '.pdf' )) {echo "<object type=" application / pdf " data=" 2010 / 2010 - March . pdf #toolbar="0"&navpanes="0" width="500" height="650" ></object>" ;}
else {echo "$month" ;}
echo "<br />" ;
?>
Line 1. Create an array
Line 2. Execute the array
Line 3. If PDF exists, embed the PDF in the page else echo the month
I tried this out and every time I get this:
Code:
Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /web/pdf/test.php on line 4
What am I missing? I have a ";" at the end of line 4.
Last edited by mhlas7; 01-11-2011 at 01:29 AM ..
01-09-2011, 07:41 PM
PM User |
#2
New Coder
Join Date: Dec 2010
Posts: 21
Thanks: 0
Thanked 1 Time in 1 Post
Code:
if (file_exists($year2.'-'.$month.'.pdf')) {echo "<object type="application/pdf" data="2010/2010-March.pdf#toolbar="0"&navpanes="0" width="500" height="650" ></object>" ;}
You open the echo with a ", but you also use " in the HTML you want to echo thus closing your echo command.
What I do to avoid such things is use ' in PHP and " in HTML.
Try this code:
Code:
if (file_exists($year2.'-'.$month.'.pdf')) {echo '<object type="application/pdf" data="2010/2010-March.pdf#toolbar="0"&navpanes="0" width="500" height="650" ></object>' ;}
01-09-2011, 07:43 PM
PM User |
#3
Senior Coder
Join Date: Aug 2003
Location: Wake Forest, North Carolina
Posts: 1,227
Thanks: 2
Thanked 189 Times in 187 Posts
Your double quotes weren't matched because you were also trying to use them around the values for the object statement. Try this instead (and if you look at what you posted with the PHP tags around it you'll see the error too
).
PHP Code:
<?php
$listmonth =array( "January" , "February" , "March" , "April" , "May" , "June" , "August" , "September" , "October" , "November" , "December" );
foreach ( $listmonth as $month ) {
if ( file_exists ( $year2 . '-' . $month . '.pdf' )) {echo '<object type="application/pdf" data="2010/2010-March.pdf#toolbar="0"&navpanes="0" width="500" height="650" ></object>' ;}
else {echo "$month" ;}
echo "<br />" ;
?>
__________________
Dave .... HostMonster for all of your hosting needs
01-10-2011, 02:41 AM
PM User |
#4
New Coder
Join Date: Jan 2011
Location: United States
Posts: 24
Thanks: 4
Thanked 0 Times in 0 Posts
Sorry
Sorry guys, when I made the first post, I left out the main problem I was having. I had a couple variables in the HTML object that I replaced with text for testing purposes. Here is the full code.
PHP Code:
<?php
$listmonth =array( "January" , "February" , "March" , "April" , "May" , "June" , "August" , "September" , "October" , "November" , "December" );
foreach ( $listmonth as $month ) {
if ( file_exists ( $year2 . '-' . $month . '.pdf' )) {echo '<object type="application/pdf" data="$year2.' - '.$month.' . pdf '#toolbar="0"&navpanes="0" width="500" height="650" ></object>' ;}
else {echo "$month" ;}
echo "<br />" ;
?>
In Line 4, I have variables in the data value. Basically what I want this code to do is if pdf exists for each month in the array, I want that pdf to be embedded in the page, else just echo the month.
Thanks for your help!
Last edited by mhlas7; 01-10-2011 at 02:56 AM ..
01-10-2011, 01:20 PM
PM User |
#5
Senior Coder
Join Date: Aug 2003
Location: Wake Forest, North Carolina
Posts: 1,227
Thanks: 2
Thanked 189 Times in 187 Posts
Other than missing a single quote or 2 and a period it appears that you almost had it. Try this which is syntax error free PHP.
PHP Code:
<?php
$listmonth =array( "January" , "February" , "March" , "April" , "May" , "June" , "August" , "September" , "October" , "November" , "December" );
foreach ( $listmonth as $month ) {
if ( file_exists ( $year2 . '-' . $month . '.pdf' )) {echo '<object type="application/pdf" data="' . $year2 . '-' . $month . '.pdf#toolbar="0"&navpanes="0" width="500" height="650" ></object>' ;}
else {echo $month ;}
echo '<br />' ;
}
?>
__________________
Dave .... HostMonster for all of your hosting needs
Users who have thanked djm0219 for this post:
01-11-2011, 01:29 AM
PM User |
#6
New Coder
Join Date: Jan 2011
Location: United States
Posts: 24
Thanks: 4
Thanked 0 Times in 0 Posts
Thanks! That worked perfectly!
Jump To Top of Thread
Thread Tools
Rate This Thread
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
All times are GMT +1. The time now is 02:32 PM .
Advertisement
Log in to turn off these ads.