Parse error: syntax error, unexpected T_STRING, expecting ',' or ';'

Discussion in 'PHP' started by Yinmy, Aug 17, 2012.

  1. #1
    Hi, I got the syntax error refering to line 108

    The relevant section of the code is shown below, the said line 108 is marked.Please help correct my syntax.Thank you


    <?php

    foreach( (array) $terms as $term){
    echo wp_get_attachment_image( $term->image_id, 'thumb' );
    echo $term->name;
    [LINE108] echo '<div style="margin: 0 10px 10px 0; float: left"><a href="’ esc_url( get_term_link( $term, $term->taxonomy ) );’"><img src=" wp_get_attachment_image( $term->image_id, 'thumb' );"></a>

    ?>
     
    Yinmy, Aug 17, 2012 IP
  2. plussy

    plussy Peon

    Messages:
    152
    Likes Received:
    5
    Best Answers:
    9
    Trophy Points:
    0
    #2
    Try this

    
     echo '<div style="margin: 0 10px 10px 0; float: left"><a href="’. esc_url( get_term_link( $term, $term->taxonomy ) ).’"><img src="'.wp_get_attachment_image( $term->image_id, 'thumb' ).'"></a>
    
    PHP:
    looks like you just copied and pasted a bunch of code together without checking anything.
     
    plussy, Aug 17, 2012 IP
  3. Yinmy

    Yinmy Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks plussy.

    Yes, I was trying to merge a bunch of codes, and ran into that problem. I am not very familiar with Php or Html.

    I have implemented your suggesion, but it seems there is still an error in the code. Now it is says "Parse error: syntax error, unexpected $end in line 103".

    Line 103 is the last line of the php file.

    It contains no code.

    Pls help.




    <div class="itembox">

    <h1>"Testing something"</h1>

    <div class="itemboxinner">


    <?php

    foreach( (array) $terms as $term){
    echo '<div style="margin: 0 10px 10px 0; float: left"><a href="’. esc_url( get_term_link( $term, $term->taxonomy ) ).’"><img src="'.wp_get_attachment_image( $term->image_id, 'thumb' ).'"></a>;


    ?>


    </div><!-- end itembox innner -->

    </div><!-- end itembox -->



    <?php get_footer();

    }

    /* =============================================================================
    -- END FILE
    ========================================================================== */
     
    Yinmy, Aug 17, 2012 IP
  4. plussy

    plussy Peon

    Messages:
    152
    Likes Received:
    5
    Best Answers:
    9
    Trophy Points:
    0
    #4
    try this then.

    
    
    
    <div class="itembox">
    
    <h1>"Testing something"</h1>
    
    <div class="itemboxinner"> 
    
    
    <?php
    
    foreach( $terms as $term){
         echo '<div style="margin: 0 10px 10px 0; float: left"><a href="'. esc_url( get_term_link( $term, $term->taxonomy ) ).'"><img src="'.wp_get_attachment_image( $term->image_id, 'thumb' ).'"></a>';
    }
    
    ?>
    
    
    </div><!-- end itembox innner -->
    
    </div><!-- end itembox --> 
    
    
    
    <?php get_footer(); 
    
    }
    
    /* =============================================================================
    -- END FILE
    ========================================================================== */
    ?>
    
    PHP:
     
    plussy, Aug 17, 2012 IP
  5. Yinmy

    Yinmy Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Dear plussy,

    Thanks for your help.
    That almost worked.

    The output is a shell with 'x' in the middle, no images.

    However, the code below gave me the images. Scattered all over.

    Other than the way the 'echo' statements are broken, I wonder what the difference is, and why the code above is returning shells and no images.



    
    
    
    <?php
    	foreach( (array) $terms as $term){
    				 echo '<div style="margin: 0 10px 10px 0; float: left">';
    			  echo '<a href="' . esc_url( get_term_link( $term, $term->taxonomy ) ) . '">' . wp_get_attachment_image( $term->image_id, 'thumb' ) . '</a>';
    	  			  echo '</li>';
    	  			  
    		  }
    
    		  
    ?>
    
    
    PHP:
    My ultimate destination is to show the images, and arrange them somewhat, like in a grid.

    Thank you
     
    Yinmy, Aug 17, 2012 IP
  6. BRUm

    BRUm Well-Known Member

    Messages:
    3,086
    Likes Received:
    61
    Best Answers:
    1
    Trophy Points:
    100
    #6
    
    foreach( (array) $terms as $term) ...
    
    Code (markup):
    Good grief, casting in PHP!? A weak typed language? Awful.
     
    BRUm, Aug 18, 2012 IP