Q:

Split a string at ";" with php

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

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="" />';
}

A:

You don't need preg_split for this.
$urls = explode(';', $string);
foreach ($urls as $url) {
    echo '<img src="'.$url.'" />';
}

