Page 1 of 1

Parse error: syntax error, unexpected T_CONSTANT

Posted: Tue Nov 29, 2011 2:42 pm
by bobbf1
Hi,

I have an array below. The individual part of the code below (starting with 'javascriptcode') is triggering a php error Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ')'

I understand the error is because " or ' are not escaped properly. I was able to remove the error from the other lines of code. For some reason, I cannot get this error for the bolded line of code to go away though.

Code: Select all

'javascriptcode' => 'setpage(\'thumb' '.$thumbnumber.'\', \''.get_permalink($wppost->ID).'\', \''.get_video_thumbnail($wppost->ID).'\')'

Code: Select all

$data = array(
						'title' => '<a class="one" href="'.get_permalink($wppost->ID).'" title="'. $title_attr .'" onMouseOver="setpage(\'thumb' .$thumbnumber.'\', \''.get_permalink($wppost->ID).'\', \''.get_video_thumbnail($wppost->ID).'\')"><span class="wpp-post-title">'. $tit .'</span></a>',
						'summary' => $post_content,
						'stats' => $stats,
						'img' => $thumb,
						'id' => $wppost->ID,
						'posttime' =>  '<span class="wpp-post-time"> (\''.get_field('video_time', $wppost->ID).'\')</span>'
						'javascriptcode' => 'setpage(\'thumb' '.$thumbnumber.'\', \''.get_permalink($wppost->ID).'\', \''.get_video_thumbnail($wppost->ID).'\')'
					);	

Re: Parse error: syntax error, unexpected T_CONSTANT

Posted: Tue Nov 29, 2011 3:01 pm
by maxx99
Nice mess you've got here :)

Try: (missing comma on after postime, one ' too much in javascriptcode

Code: Select all

<?php

$data = array( 'title' => '<a class="one" href="'.get_permalink($wppost->ID).'" title="'. $title_attr .'" onMouseOver="setpage(\'thumb' .$thumbnumber.'\', \''.get_permalink($wppost->ID).'\', \''.get_video_thumbnail($wppost->ID).'\')"><span class="wpp-post-title">'. $tit .'</span></a>',
                                                 'summary' => $post_content,
                                                 'stats' => $stats,
                                                 'img' => $thumb,
                                                 'id' => $wppost->ID,
                                                 'posttime' =>  '<span class="wpp-post-time"> (\''.get_field('video_time', $wppost->ID).'\')</span>',
                                                 'javascriptcode' => 'setpage(\'thumb' .$thumbnumber.'\', \''.get_permalink($wppost->ID).'\', \''.get_video_thumbnail($wppost->ID).'\')'
                                         );  
?>

Re: Parse error: syntax error, unexpected T_CONSTANT

Posted: Tue Nov 29, 2011 3:58 pm
by bobbf1
Thanks that worked!

It is quite a mess. I am editing someone else's wordpress plugin and my eyes are glazing over :)