jaymc Posted October 7, 2006 Share Posted October 7, 2006 Ok, lets drop you right in it[quote]$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[code]<OPTION>108/1727.wma</OPTION><OPTION>108/1734.wma</OPTION>ect..[/code]You get the drift, anyway, when they select one and submit, it needs to remove their selection from $stringSo, 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 pipeNow 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] Quote Link to comment Share on other sites More sharing options...
redarrow Posted October 7, 2006 Share Posted October 7, 2006 str_replace(); Quote Link to comment Share on other sites More sharing options...
jaymc Posted October 7, 2006 Author Share Posted October 7, 2006 [quote author=redarrow link=topic=110817.msg448602#msg448602 date=1160242972]str_replace();[/quote]Lol. You dont get itIf 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[b]|108/1734.wma|108/1725.wma|108/1737.wma|108/1732.wma|108/1730.wma|108/1738.wma[/b]Hence, a PIPE at the start ! Which cant be done! Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted October 7, 2006 Share Posted October 7, 2006 [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:<?php$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]); return(implode('|',$a));}?>[/code]Ken Quote Link to comment Share on other sites More sharing options...
jaymc Posted October 7, 2006 Author Share Posted October 7, 2006 Worked a charm! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.