Reputation: 35
I'm trying to link to an image from a path in my dir. How can I escape the variable properly?
Here's my code:
foreach ($images as $row) {
$config['source_image'] = '/assets/images/'.$row;
}
The $row variable needs to be in between single quotes. Thanks
Upvotes: 1
Views: 54
Reputation: 3847
Why not use double quotes like the following.
foreach ($images as $row) {
$config['source_image'] = "/assets/images/{$row}";
}
Or do you need it in single quotes?
Upvotes: 0
Reputation: 10617
Try the following:
foreach($images as $i => $v){
$config[$i] = rawurlencode("/assets/images/$v");
}
Now the $config
array takes on the names or numbers, depending on the type of array $images
is, of the $images
array.
Upvotes: 0
Reputation: 83
foreach ($images as $row) {
$config['source_image'] = '/assets/images/'.$row.';
}
Your code is perfectly fine the way it is tho.
Upvotes: 1