psychowolvesbane Posted January 12, 2008 Share Posted January 12, 2008 I have a string "Ash?Black?Orange?Red?Yellow?White?" that is created by concatenating multiple results from a checkbox selection on a form, and I know need to retrieve each value or colour name that occurs before the character "?" and place them into an array, then display all the contents of that array. Can you show me how that can be done? The variable that contains the string is $AvailableColoursStr and the variable $ToFind = "?", and the output should be in a variable called $AvailableColours. Quote Link to comment https://forums.phpfreaks.com/topic/85735-solved-string-retrieval-help/ Share on other sites More sharing options...
Ken2k7 Posted January 12, 2008 Share Posted January 12, 2008 $AvailableColours = explode($ToFind, $AvailableColursStr); That would put them all in the array. Quote Link to comment https://forums.phpfreaks.com/topic/85735-solved-string-retrieval-help/#findComment-437538 Share on other sites More sharing options...
psychowolvesbane Posted January 12, 2008 Author Share Posted January 12, 2008 I get this in return: Warning: explode() [function.explode]: Empty delimiter. in /home/www/psychowolvesbane.freehostia.com/details.inc on line 29 Line 29: <p><?php echo "Available Colours: " . $AvailableColours; ?></p> Quote Link to comment https://forums.phpfreaks.com/topic/85735-solved-string-retrieval-help/#findComment-437540 Share on other sites More sharing options...
Ken2k7 Posted January 12, 2008 Share Posted January 12, 2008 Think I spelled the variable wrong $AvailableColours = explode($ToFind, $AvailableColoursStr); Quote Link to comment https://forums.phpfreaks.com/topic/85735-solved-string-retrieval-help/#findComment-437544 Share on other sites More sharing options...
psychowolvesbane Posted January 12, 2008 Author Share Posted January 12, 2008 No I spotted that. It must be something to do with how I am displaying them, does the Explode function use an array as an output method? Quote Link to comment https://forums.phpfreaks.com/topic/85735-solved-string-retrieval-help/#findComment-437545 Share on other sites More sharing options...
trq Posted January 12, 2008 Share Posted January 12, 2008 Post your current code. Quote Link to comment https://forums.phpfreaks.com/topic/85735-solved-string-retrieval-help/#findComment-437546 Share on other sites More sharing options...
psychowolvesbane Posted January 12, 2008 Author Share Posted January 12, 2008 $AvailableColoursStr = $record['AvailableColours']; (This is the database record retrieval, works fine as I'm just trying to update an already working page) $AvailableColours = explode($ToFind, $AvailableColoursStr); Output: <p><?php echo "Available Colours: " . $AvailableColours; ?></p> Quote Link to comment https://forums.phpfreaks.com/topic/85735-solved-string-retrieval-help/#findComment-437555 Share on other sites More sharing options...
Ken2k7 Posted January 12, 2008 Share Posted January 12, 2008 $AvailableColours isn't a string. It's an array. Try: $AvailableColours = implode(", ",explode($ToFind, $AvailableColoursStr)); Quote Link to comment https://forums.phpfreaks.com/topic/85735-solved-string-retrieval-help/#findComment-437557 Share on other sites More sharing options...
psychowolvesbane Posted January 12, 2008 Author Share Posted January 12, 2008 That just added this to the error list: Warning: explode() [function.explode]: Empty delimiter. in /home/www/psychowolvesbane.freehostia.com/details.inc on line 29 Warning: implode() [function.implode]: Bad arguments. in /home/www/psychowolvesbane.freehostia.com/details.inc on line 29 Same code as you posted. Quote Link to comment https://forums.phpfreaks.com/topic/85735-solved-string-retrieval-help/#findComment-437561 Share on other sites More sharing options...
Ken2k7 Posted January 12, 2008 Share Posted January 12, 2008 Ohk, can you post your code. Quote Link to comment https://forums.phpfreaks.com/topic/85735-solved-string-retrieval-help/#findComment-437563 Share on other sites More sharing options...
psychowolvesbane Posted January 12, 2008 Author Share Posted January 12, 2008 I still think the output should have some method of array extraction, atm it seems only capable of displaying normal values. $AvailableColoursStr = $record['AvailableColours']; (Input) $AvailableColours = implode(", ",explode($ToFind, $AvailableColoursStr)); (Process) <p><?php echo "Available Colours: " . $AvailableColours; ?></p> (Output) Quote Link to comment https://forums.phpfreaks.com/topic/85735-solved-string-retrieval-help/#findComment-437567 Share on other sites More sharing options...
Ken2k7 Posted January 12, 2008 Share Posted January 12, 2008 I got that part. Can you post more of your code? You sure $ToFind is defined? Quote Link to comment https://forums.phpfreaks.com/topic/85735-solved-string-retrieval-help/#findComment-437569 Share on other sites More sharing options...
psychowolvesbane Posted January 12, 2008 Author Share Posted January 12, 2008 Well the only parts that concern this are those lines and a single line that defines $toFine with: $tofind = "?"; As I mentioned before the rest of the code works already, I'm just adding a new feature to it in a very localized area. Also if you need a reminder: $AvailableColoursStr ="Ash?Black?Orange?Red?Yellow?White?" or something similar depending on what colours were chosen in a separate form. Quote Link to comment https://forums.phpfreaks.com/topic/85735-solved-string-retrieval-help/#findComment-437573 Share on other sites More sharing options...
trq Posted January 12, 2008 Share Posted January 12, 2008 So have you defined $tofind or $ToFind ? They are two different variables. Quote Link to comment https://forums.phpfreaks.com/topic/85735-solved-string-retrieval-help/#findComment-437575 Share on other sites More sharing options...
psychowolvesbane Posted January 12, 2008 Author Share Posted January 12, 2008 Ah thank you I didn't think it would affect it like that, it works great now, thanks! Quote Link to comment https://forums.phpfreaks.com/topic/85735-solved-string-retrieval-help/#findComment-437578 Share on other sites More sharing options...
psychowolvesbane Posted January 12, 2008 Author Share Posted January 12, 2008 However before I finish, is there a way to actually enter each colour into an array for retrieval without posting them all at once? I need to display them in a table with each colour in separate columns in a later part of my website. Quote Link to comment https://forums.phpfreaks.com/topic/85735-solved-string-retrieval-help/#findComment-437581 Share on other sites More sharing options...
psychowolvesbane Posted January 12, 2008 Author Share Posted January 12, 2008 Anyone? Quote Link to comment https://forums.phpfreaks.com/topic/85735-solved-string-retrieval-help/#findComment-437584 Share on other sites More sharing options...
Ken2k7 Posted January 13, 2008 Share Posted January 13, 2008 You could have waited more than 10 minutes. Read the rules. $AvailableColours = explode($toFind, $AvailableColoursStr); Quote Link to comment https://forums.phpfreaks.com/topic/85735-solved-string-retrieval-help/#findComment-437600 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.