StevenWin
StevenWin

Reputation: 35

Making a filename in a path dynamic

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

Answers (3)

TURTLE
TURTLE

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

StackSlave
StackSlave

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

user3316397
user3316397

Reputation: 83

foreach ($images as $row) {

$config['source_image'] = '/assets/images/'.$row.';

}

Your code is perfectly fine the way it is tho.

Upvotes: 1

Related Questions