Jump to content


Photo

A bit messy but...


  • Please log in to reply
4 replies to this topic

#1 jaymc

jaymc
  • Members
  • PipPipPip
  • Advanced Member
  • 1,521 posts
  • LocationLiverpool

Posted 07 October 2006 - 05:40 PM

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


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

<OPTION>108/1727.wma</OPTION>
<OPTION>108/1734.wma</OPTION>
ect..


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

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

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


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

Any help?




I would love to change the world, but they won't give me the source code

SEO Agency

#2 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 07 October 2006 - 05:42 PM

str_replace();
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#3 jaymc

jaymc
  • Members
  • PipPipPip
  • Advanced Member
  • 1,521 posts
  • LocationLiverpool

Posted 07 October 2006 - 05:46 PM

str_replace();

Lol. You dont get it

If I use str_replace it would be like this

$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);

$newstring would come out like this

|108/1734.wma|108/1725.wma|108/1737.wma|108/1732.wma|108/1730.wma|108/1738.wma

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

I would love to change the world, but they won't give me the source code

SEO Agency

#4 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 07 October 2006 - 05:48 PM

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));
}
?>

Ken

#5 jaymc

jaymc
  • Members
  • PipPipPip
  • Advanced Member
  • 1,521 posts
  • LocationLiverpool

Posted 07 October 2006 - 08:34 PM

Worked a charm!
I would love to change the world, but they won't give me the source code

SEO Agency




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users