Jump to content


This topic is now archived and is closed to further replies.


A bit messy but...

Recommended Posts

Ok, lets drop you right in it

$string = 108/1727.wma|108/1734.wma|108/1725.wma|108/1737.wma|108/1732.wma|108/1730.wma|108/1738.wma[/quote]

I have a form which contains a drop down with each of the above in OPTIONS


You get the drift, anyway, when they select one and submit, it needs to remove their selection from $string

So, if they selected [b]<OPTION>108/1727.wma</OPTION>[/b] then the string would need to be modified to

[quote]$string = 108/1734.wma|108/1725.wma|108/1737.wma|108/1732.wma|108/1730.wma|108/1738.wma[/quote]

That bit is simple so far right? well, the problem is, those pipes need to be in the correct places. The string can never start with a pipe, and it can never end with a pipe

Now if you have thought ahead, you will see that if they submit to delete either
* 108/1727.wma
* 108/1738.wma

$string will be left with either a pipe at the start or end of the $string.

How can I get around this. Its a bit messy, but I've been working on this for over an hour and cant get my head around it

[b]Any help?[/b]

Share this post

Link to post
Share on other sites
[quote author=redarrow link=topic=110817.msg448602#msg448602 date=1160242972]
Lol. You dont get it

If I use str_replace it would be like this

[code]$string = 108/1727.wma|108/1734.wma|108/1725.wma|108/1737.wma|108/1732.wma|108/1730.wma|108/1738.wma

$newstring = str_replace("108/1727.wma", "", $string);[/code]

$newstring would come out like this


Hence, a PIPE at the start ! Which cant be done!

Share this post

Link to post
Share on other sites
[code]Use the [url=http://www.php.net/explode]explode()[/url] function to create an array out of the string, unset the correct entry in the array and use the [url=http://www.php.net/implode()[/url] functioin to recreate the string.

Something like this:
$string = '108/1727.wma|108/1734.wma|108/1725.wma|108/1737.wma|108/1732.wma|108/1730.wma|108/1738.wma';
$option = '108/1727.wma';
echo $string.'<br>';
$string = remove_option($string,$option);
echo $string;

function remove_option($s,$o) {
    $a = explode('|',$s);
    for ($i=0;$i<count($a);$i++)
        if ($a[$i] == $o) unset($a[$i]);


Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.