Link to home
Start Free TrialLog in
Avatar of rotemweb

asked on

Extract each URL from a list of semicoma-separated URLS


In my database table I have a field named "photoURL" but it doesn't contain just one URL, but a list of semicoma-separated URLS.

I want to know how to extract each URL and put it in a variable ( knowing that I can't tell the number of URLS included in each entry...)

I guess it can be made by a RegExpression or a IndexOf, but I have no idea how to apply it.

THanks for your help! (see code below)

$bighotels = mysql_query("SELECT photoURL,name FROM hotels_mars08"); 
                        //and later in the page 
while ($bighotels_list = mysql_fetch_array($bighotels) )
echo \<img src=\"$bighotels_list['photoURL']\" alt=\"hotel echo $bighotels_list['name'];\" /\>
// exemple of value rerieved by' 'photoURL';;;;

Open in new window

Avatar of Cornelia Yoder
Cornelia Yoder
Flag of United States of America image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ooops, sorry, you said SEMICOLON separated, my bad:

$array = explode(":", $urlstringlist);
If you accept my comment, what you are doing is not correct.  you said that you are not sure how many URLs will be in this field, which means that the way you set up the table is wrong,  in the following post I will suggest you a better way to set up your table.
check this one out.

Note: you code got allot of typos.

Table 1                               Table 2
=======                               =======
hotel_id -------------------------->  hotel_id
hotel_name                            image_name
This way you can have several hotels and for each hotel you will have as many hotel images as it needs.
$bighotels = mysql_query("SELECT t2.photoURL as photoUrl,t2.image_name as name FROM table1 t1, table2 t2 where t1.hotel_id = t2.hotel_id and t1.hotel_id = '$hotel_id'");
while ($bighotels_list = mysql_fetch_array($bighotels) )
echo "<img src=\"$bighotels_list['photoUrl']\" alt=\"hotel\">$bighotels_list['name']\" />";
// exemple of value rerieved by' 'photoURL';;;; 
Open in New Window 

Open in new window

Avatar of rotemweb


Excellent, just what I needed. You could have precised the general ruel though, but since you indicated the link where it is explicated, it is just as ell :) (thought this link might not eternally work!)
ehabafia, thnks for your help but your answer is way too complicated, and not necessary. I don't wanna reorganize a whole table, since it has mor than 15000 entries. Moreover, it was given to me as it is, i had no choice.

youdercm was right, i just create the array thanks to

explode(";", $thelistofurls);

  Then looped into  the array to show the images:

 for ($countimg=0; $countimg < count($imageslist_array)  ;$countimg++)
             $currentimg=$imageslist_array[$countimg ]; $currentalt=$bighotels_list['name'];
              echo "<img src='$currentimg' alt='$currentalt' />";

That's all , thank you both