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] Link to comment https://forums.phpfreaks.com/topic/23294-a-bit-messy-but/ Share on other sites More sharing options...
redarrow Posted October 7, 2006 Share Posted October 7, 2006 str_replace(); Link to comment https://forums.phpfreaks.com/topic/23294-a-bit-messy-but/#findComment-105600 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! Link to comment https://forums.phpfreaks.com/topic/23294-a-bit-messy-but/#findComment-105604 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 Link to comment https://forums.phpfreaks.com/topic/23294-a-bit-messy-but/#findComment-105608 Share on other sites More sharing options...
jaymc Posted October 7, 2006 Author Share Posted October 7, 2006 Worked a charm! Link to comment https://forums.phpfreaks.com/topic/23294-a-bit-messy-but/#findComment-105656 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.