Jump to content

Recommended Posts

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>");

 

 

Link to comment
https://forums.phpfreaks.com/topic/239556-help-with-syntax-in-array/
Share on other sites

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

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;

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

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.