Jump to content

help with syntax in array


dflow

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

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