D
D
Dima Pautov2015-12-09 19:53:39
PHP
Dima Pautov, 2015-12-09 19:53:39

How to substitute a string for the value of a variable?

There is a line _huge_it_small_gallery .
There is a variable that contains the full path to the image.
Example:
/uploads/2015/12/header3.jpg
Help me figure out how to make it so that it would turn out like this:
/uploads/2015/12/header3_huge_it_small_gallery.jpg
Here is my forych:

foreach ($query as $img) {
    $carouselItems .= '<li><a href="'.$img->image_url.'" class="carouselItem" rel="fancyboxCarousel'.$id.'"><img src="'.$img->image_url.'"></a></li>';
  }

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Andrew, 2015-12-09
@bootd

<?php

foreach ($query as $img) {
  $img->image_url = str_replace(".jpg", "_huge_it_small_gallery.jpg", $img->image_url);
  $carouselItems .= '<li><a href="'.$img->image_url.'" class="carouselItem" rel="fancyboxCarousel'.$id.'"><img src="'.$img->image_url.'"></a></li>';
}

V
Vladimir Maltsev, 2015-12-09
@mrhard

if you don't sweat
Either you cut the file resolution, shove between the line _huge_it_small_gallery and collect everything together
or regular expressions.

O
Optimus, 2015-12-09
Pyan @marrk2

$p = '_huge_it_small_gallery';
$full = '/uploads/2015/12/header3'.$p.'.jpg';

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question