snday Posted January 8, 2007 Share Posted January 8, 2007 if i do this:[code=php:0]$foo = "one=1,two=2,three=3,four=4";$foo = explode(",", $foo);echo $foo[0];echo $foo[1];echo $foo[2];echo $foo[3];[/code]it will output:[b]one=1two=2three=3four=4[/b]How can I make it only output the numbers and take away the one=/two=/etc IF the one=/two=/etc could be dynamic and not always known? Link to comment https://forums.phpfreaks.com/topic/33280-solved-explode-help/ Share on other sites More sharing options...
DarkendSoul Posted January 8, 2007 Share Posted January 8, 2007 You could explode it a second time, exploding with ='s sign.Like such.[code]<?php$foo = "one=1,two=2,three=3,four=4";$foo = explode(",", $foo);$i=0;while ($foo[$i]) {$findNumber=explode("=", $foo[$i]);$number[$i]=$findNumber[1];$word[$i]=$findNumber[0];$i++;}echo $number[0]."<br />\n";echo $word[1]."<br />\n";echo $foo[2]."<br />\n";echo $number[3]."<br />\n";?>[/code]Tested, working, code. Link to comment https://forums.phpfreaks.com/topic/33280-solved-explode-help/#findComment-155475 Share on other sites More sharing options...
magic2goodil Posted January 8, 2007 Share Posted January 8, 2007 You can;t explode an array dark Link to comment https://forums.phpfreaks.com/topic/33280-solved-explode-help/#findComment-155476 Share on other sites More sharing options...
DarkendSoul Posted January 8, 2007 Share Posted January 8, 2007 Code posted and tested, it works magic2goodil. ;) Link to comment https://forums.phpfreaks.com/topic/33280-solved-explode-help/#findComment-155481 Share on other sites More sharing options...
magic2goodil Posted January 8, 2007 Share Posted January 8, 2007 Try this:[code]$foo = "one=1,two=2,three=3,four=4"; $myArray = explode(',', $foo); $newArray = array(count($myArray)); $count = 0; //loops back through a new array of size $i //creates new array with pointer and value while($count < count($myArray)) { //breaking down urlArray into array pointer and array value //also destroying those evil = signs foreach($myArray as $row) { $pointer = substr($url, 0, strpos($row, "=")); $value = substr($row, strpos($row, "=") + 1, strlen($row)); $newArray["$pointer"] = $value; } //end foreach $count++; } //end while [/code]yeah, but u exploded the single spot of the array and had to do it for each one...if he tries this code, it gives a new array with the = taken out and his original keys intact Link to comment https://forums.phpfreaks.com/topic/33280-solved-explode-help/#findComment-155484 Share on other sites More sharing options...
DarkendSoul Posted January 8, 2007 Share Posted January 8, 2007 I dont believe that magic2goodil's code will work if you move up to 2 digit numbers or more...ten=10,forty=40,nine hundred=900try. Link to comment https://forums.phpfreaks.com/topic/33280-solved-explode-help/#findComment-155487 Share on other sites More sharing options...
snday Posted January 8, 2007 Author Share Posted January 8, 2007 [quote author=DarkendSoul link=topic=121447.msg499431#msg499431 date=1168223649]Code posted and tested, it works magic2goodil. ;)[/quote]yes, and that is awesome and i thank you.Doing it the way you posted also means I can retain any value from the originalwhich is an awesome added bonus!magic2goodil, thanks for your suggestion.I think DarkendSoul's solution better suites my needs :) Link to comment https://forums.phpfreaks.com/topic/33280-solved-explode-help/#findComment-155488 Share on other sites More sharing options...
magic2goodil Posted January 8, 2007 Share Posted January 8, 2007 :p DarkenedSoul 1 Magic 0You win this round, but next time I wont go so easy on you!lol Link to comment https://forums.phpfreaks.com/topic/33280-solved-explode-help/#findComment-155490 Share on other sites More sharing options...
DarkendSoul Posted January 8, 2007 Share Posted January 8, 2007 Remember to make your post as solved.&&A coding war is it? We'll see. Link to comment https://forums.phpfreaks.com/topic/33280-solved-explode-help/#findComment-155493 Share on other sites More sharing options...
snday Posted January 8, 2007 Author Share Posted January 8, 2007 [quote author=magic2goodil link=topic=121447.msg499446#msg499446 date=1168224385]:p DarkenedSoul 1 Magic 0You win this round, but next time I wont go so easy on you!lol[/quote][quote author=DarkendSoul link=topic=121447.msg499449#msg499449 date=1168224467]Remember to make your post as solved.&&A coding war is it? We'll see.[/quote]lol!Thanks for the help all and I almost forgot to 'solve topic' :P Link to comment https://forums.phpfreaks.com/topic/33280-solved-explode-help/#findComment-155497 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.