Jump to content

A bit messy but...


jaymc

Recommended Posts

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 $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]



Link to comment
Share on other sites

[quote author=redarrow link=topic=110817.msg448602#msg448602 date=1160242972]
str_replace();
[/quote]
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

[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
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:
<?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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.