views:

52

answers:

4

I have a string called $gallery, $gallery is a list of image URLS The image urls are seperated by a semi- colon ;. Example

http://www.website.com/image1.jpg;http://www.website.com/image2.jpg;http://www.website.com/image3.jpg

How can I split this up and place each url in an image tag, I suppose using preg_split?

Thanks

+4  A: 

No need for regular expressions with preg_split(), just a simple regex-less explode() will do since they're delimited by a semicolon.

foreach (explode(';', $gallery) as $url) {
    echo '<img src="' . htmlspecialchars($url, ENT_QUOTES) . '" alt="" />';
}
BoltClock
+4  A: 

You don't need preg_split for this.

$urls = explode(';', $string);
foreach ($urls as $url) {
    echo '<img src="'.$url.'" />';
}
Tim Fountain
`echo '<img src="'.htmlspecialchars($url).'" />';`
Tomalak
A: 
$urls = explode(';', $gallery);
foreach ($link as $Val) {
    echo '<img src="'.$Val.'" />';
}
seed_of_tree
+2  A: 

You can use str_replace

'<img src="' . str_replace(';','" /><img src="',$gallery) . '" />';
AntonioCS