Lokendra Panwar Lokendra Panwar - 5 months ago 11
PHP Question

How to concatenate string in php?

How to concatenate string in image source. I try to set base path dynamic in image source but it does not work. I am also using in fore each loop. any body can help me, give me some suggestion. I am new in php.

Here is my php code-

$base_path = 'https://odesk.com';

$listing = '';
$count=1;
if(sizeOf($entry['contents'])>0){
foreach($entry['contents'] as $child) {
$count++;
$cp = $child['path'];
$cn = basename($cp);
$image='';

$cp = htmlspecialchars($cp);
$link = getPath("?path=".htmlspecialchars($cp));

if ($child['is_dir'])
{

$image ='<img src="'@$base_path'/images/folder.png" width="20">';// i want here add base path
$cn .= '/';
}else{
$image ='<input type="checkbox" value="'.$child['rev'].'" id="'.$child['rev'].'" name="checkbox_value[]" onclick="saveimages('.@$_SESSION['products_id'].',`'.@$path.'`,`'.@$cn.'`,this.value,event)" class="checked">&nbsp;<img src="https://odesk.com/images/image_dropbox.png" width="15">';
}


if($count%2==0){
$listing .= "<div class='white'>$image&nbsp;<a id='a1' style='text-decoration: none;vertical-align:super;color:black;' href='$link'>$cn</a></div>";
}else{
$listing .= "<div class='white'>$image&nbsp;<a id='a1' style='text-decoration: none;vertical-align:super;color:black;' href='$link'>$cn</a></div>";
}

}
}else{
$listing = "<div align='center' class='white'><span style='color:red; text-align:center;'>No folders & files are available.</span></div>";
}

Answer

We use . for concatenating values in PHP.

Replace following line

$image ='<img src="'@$base_path'/images/folder.png" width="20">';/

with

$image ='<img src="'.$base_path.'/images/folder.png" width="20">';/
Comments