dflow Posted June 16, 2011 Share Posted June 16, 2011 i have this array, i want to change the link phrase with a variable i get his error: Parse error: syntax error, unexpected T_VARIABLE, expecting ')' in city.php on line 58 this is line 58,59 $with=array("<a href='index.html'>index</a>", "<a href='index.html'>$xmlcitydata->data->city</a>"); Quote Link to comment https://forums.phpfreaks.com/topic/239556-help-with-syntax-in-array/ Share on other sites More sharing options...
gristoi Posted June 16, 2011 Share Posted June 16, 2011 you will find that errors of this nature are not usually on the line in question. what is on the lines preceding this one? Quote Link to comment https://forums.phpfreaks.com/topic/239556-help-with-syntax-in-array/#findComment-1230557 Share on other sites More sharing options...
redixx Posted June 16, 2011 Share Posted June 16, 2011 Concatenating seemed to work for me. $with=array("<a href='index.html'>index</a>", "<a href='index.html'>" . $xmlcitydata->data->city . "</a>"); If not, then this isn't the line with the error. Quote Link to comment https://forums.phpfreaks.com/topic/239556-help-with-syntax-in-array/#findComment-1230589 Share on other sites More sharing options...
mikesta707 Posted June 16, 2011 Share Posted June 16, 2011 judging from the error, you are missing a closing parenthesis on the line(s) above Quote Link to comment https://forums.phpfreaks.com/topic/239556-help-with-syntax-in-array/#findComment-1230591 Share on other sites More sharing options...
dflow Posted June 16, 2011 Author Share Posted June 16, 2011 Concatenating seemed to work for me. $with=array("<a href='index.html'>index</a>", "<a href='index.html'>" . $xmlcitydata->data->city . "</a>"); If not, then this isn't the line with the error. excellent did the job thank you all Quote Link to comment https://forums.phpfreaks.com/topic/239556-help-with-syntax-in-array/#findComment-1230600 Share on other sites More sharing options...
dflow Posted June 19, 2011 Author Share Posted June 19, 2011 i have a new problem with this when adding extra $vars this works: $with=array("<a href='index.html'>index</a>", "<a href='".$xmlcitydata->data->main_backlink_rt_1 .'/'.$xmlcitydata->data->city_name."'.html'>".$xmlcitydata->data->city_kw_1_rt_1."</a>"); and i wan this to work as well $with=array("<a href='index.html'>index</a>", "<a href='".$xmlcitydata->data->main_backlink_rt_1 .'/'.$xmlcitydata->data->city_name."'.html'>".$xmlcitydata->data->city_kw_1_rt_1.$xmlcitydata->data->city_name"</a>"); error received: Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ')' error is for adding this .$xmlcitydata->data->city_name Quote Link to comment https://forums.phpfreaks.com/topic/239556-help-with-syntax-in-array/#findComment-1231735 Share on other sites More sharing options...
cyberRobot Posted June 19, 2011 Share Posted June 19, 2011 Looks like you're missing a dot near the end. This: city_kw_1_rt_1.$xmlcitydata->data->city_name"</a>"); Should be: city_kw_1_rt_1.$xmlcitydata->data->city_name."</a>"); Quote Link to comment https://forums.phpfreaks.com/topic/239556-help-with-syntax-in-array/#findComment-1231740 Share on other sites More sharing options...
redixx Posted June 19, 2011 Share Posted June 19, 2011 In the interest of readable code, I would suggest to you that you add spaces around concatenation to help you see where variables separate from the string. Whitespace won't be parsed so it won't cause any errors. // instead of echo 'blahblah'.$variable.'blahblahblah'.$variable2; // do echo 'blahblah' . $variable . 'blahblahblah' . $variable2; Quote Link to comment https://forums.phpfreaks.com/topic/239556-help-with-syntax-in-array/#findComment-1231750 Share on other sites More sharing options...
kenrbnsn Posted June 19, 2011 Share Posted June 19, 2011 A more readable version would be to use "{ }" around the variables: <?php $with=array("<a href='index.html'>index</a>", "<a href='{$xmlcitydata->data->main_backlink_rt_1}/{$xmlcitydata->data->city_name}.html'>{$xmlcitydata->data->city_kw_1_rt_1}</a>"); ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/239556-help-with-syntax-in-array/#findComment-1231776 Share on other sites More sharing options...
dflow Posted June 21, 2011 Author Share Posted June 21, 2011 A more readable version would be to use "{ }" around the variables: <?php $with=array("<a href='index.html'>index</a>", "<a href='{$xmlcitydata->data->main_backlink_rt_1}/{$xmlcitydata->data->city_name}.html'>{$xmlcitydata->data->city_kw_1_rt_1}</a>"); ?> great this just solved another problem thanks! Ken Quote Link to comment https://forums.phpfreaks.com/topic/239556-help-with-syntax-in-array/#findComment-1232755 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.