How do I get multiple images from a single string
-
I've looked around and haven't found a answer that did it for me. I don't want all the images from an HTML page. I just want all the images from a single string. On a page, I'm using two different strings. I want all the images that are within the second image. I want to loop them into a carousel. I've looked around a bit and this is what I got: function GetImgString($plaatje){ preg_match_all('/<img[^>]+>/i',$plaatje, $result); $house = $result[0]; $i = 1; $output = '<div class="carousel-inner">'; foreach ( $house as $houses ) { if ($i == 1) { $output.= '<div class="item active">'; }else{ $output.= '<div class="item">'; } $output.= $house.' <div class="container"> <div class="carousel-caption"> </div> </div> </div> '; $i++; } $output .= '</div>'; return $house;} This is the output: Array ( [0] => <img src="images/Huizen/huis-3.jpg" alt="" /> [1] => <img src="images/Huizen/huis-4.jpg" alt="" /> ) How do I solve this?
-
Answer:
I assume, when you do the regexp, in your results, there are the 2 images. You are start to building your output into a variable, calles $output, but you return with $house, what contain the 2 result from preg_match. So you can try with this: function GetImgString($plaatje) { preg_match_all('/<img[^>]+>/i', $plaatje, $result); $houses = $result[0]; $houses = str_ireplace('<', '<', $house); $houses = str_ireplace('>', '>', $house); $i = 1; $output = '<div class="carousel-inner">'; foreach ($houses as $house) { $class = ' class="item"'; if ($i === 1) { $class = ' class="item active"'; } $output.= '<div '.$class.'>'; $output.= $house . ' <div class="container"> <div class="carousel-caption"></div> </div> </div>' . "\n"; $i++; } $output .= '</div>'; return $output; }
ToluT at Stack Overflow Visit the source
Related Q & A:
- How do I upload multiple files into a folder?Best solution by Yahoo! Answers
- How do I get multiple names for me on myspace?Best solution by Yahoo! Answers
- How do I get thinner legs and a flat stomach?Best solution by Yahoo! Answers
- How can i get backstage passes to a concert?Best solution by Yahoo! Answers
- How do I connect multiple monitors on a mac? Is it possible?Best solution by cnet.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.