Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #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.

  • #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>' ;}

  • #3
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,300
    Thanks
    4
    Thanked 203 Times in 200 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

  • #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.

  • #5
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,300
    Thanks
    4
    Thanked 203 Times in 200 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:

    mhlas7 (01-11-2011)

  • #6
    New Coder
    Join Date
    Jan 2011
    Location
    United States
    Posts
    24
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Thanks! That worked perfectly!


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •