Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-09-2011, 07:24 PM   PM User | #1
mhlas7
New Coder

 
Join Date: Jan 2011
Location: United States
Posts: 24
Thanks: 4
Thanked 0 Times in 0 Posts
mhlas7 is an unknown quantity at this point
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..
mhlas7 is offline   Reply With Quote
Old 01-09-2011, 07:41 PM   PM User | #2
dbrekelmans
New Coder

 
Join Date: Dec 2010
Posts: 21
Thanks: 0
Thanked 1 Time in 1 Post
dbrekelmans is an unknown quantity at this point
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>' ;}
dbrekelmans is offline   Reply With Quote
Old 01-09-2011, 07:43 PM   PM User | #3
djm0219
Senior Coder

 
djm0219's Avatar
 
Join Date: Aug 2003
Location: Wake Forest, North Carolina
Posts: 1,227
Thanks: 2
Thanked 189 Times in 187 Posts
djm0219 is on a distinguished road
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
djm0219 is offline   Reply With Quote
Old 01-10-2011, 02:41 AM   PM User | #4
mhlas7
New Coder

 
Join Date: Jan 2011
Location: United States
Posts: 24
Thanks: 4
Thanked 0 Times in 0 Posts
mhlas7 is an unknown quantity at this point
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..
mhlas7 is offline   Reply With Quote
Old 01-10-2011, 01:20 PM   PM User | #5
djm0219
Senior Coder

 
djm0219's Avatar
 
Join Date: Aug 2003
Location: Wake Forest, North Carolina
Posts: 1,227
Thanks: 2
Thanked 189 Times in 187 Posts
djm0219 is on a distinguished road
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
djm0219 is offline   Reply With Quote
Users who have thanked djm0219 for this post:
mhlas7 (01-11-2011)
Old 01-11-2011, 01:29 AM   PM User | #6
mhlas7
New Coder

 
Join Date: Jan 2011
Location: United States
Posts: 24
Thanks: 4
Thanked 0 Times in 0 Posts
mhlas7 is an unknown quantity at this point
Thanks! That worked perfectly!
mhlas7 is offline   Reply With Quote
Reply

Bookmarks

Tags
html, pdf, php

Jump To Top of Thread


Thread Tools
Rate This Thread
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

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

Forum Jump


All times are GMT +1. The time now is 02:32 PM.


Advertisement
Log in to turn off these ads.