eloism eloism - 1 year ago 79
PHP Question

merge several strings with a separator in one variable, and seperate them once the variable is called

On my website I need to store several urls on my database.

Rather than storing each of them in a different row I chose to put them all in a single row (since when I call them, I need them all anyways).

To do that I store the urls in a single string separated by

like this :


My question is, once I get this string back in a variable, how can I get back each of theses links in order to put them inside individual span ?
Like :


Answer Source

What you search is the function explode.

$yourString = 'http://url1.com/dhsg.php||http://url2.com/jjipg.php||http://url3.com/dbhm.php||http://url4.com/dheresg.php';

$arrayWithURLs = explode('||', $yourString);

echo '<pre>' . print_r($arrWithURLs, TRUE) . '</pre>';

The last echo gives you the result in readable form.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download