canadabeeau Posted December 13, 2009 Share Posted December 13, 2009 Hi PHPers, I have a PHP string like this: 00:4A:88:66:BB:AA 0Z:8A:44:99:AB:BA 00:00:00:00:00:00:00:e0 00:00:00:00:00:00:00:e0 00:00:00:00:00:00:00:e0 but sometimes it may be longer. I need a way that will remove all the "00:00:00:00:00:00:00:e0" then split whatever is left at the spaces and then tell me how many array's it made. So basically I need it to get 00:4A:88:66:BB:AA 0Z:8A:44:99:AB:BA 00:00:00:00:00:00:00:e0 00:00:00:00:00:00:00:e0 delete all 00:00:00:00:00:00:00:e0 so it becomes 00:4A:88:66:BB:AA 0Z:8A:44:99:AB:BA split them at the spaces so then I have array[1] = 00:4A:88:66:BB:AA and array[2] = 0Z:8A:44:99:AB:BA and $Numberofarrays = 2 . Any help appreciated and thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/184967-php-string/ Share on other sites More sharing options...
RussellReal Posted December 13, 2009 Share Posted December 13, 2009 $array = explode(' ',str_replace("00:00:00:00:00:00:00:e0","",$originalString)); Quote Link to comment https://forums.phpfreaks.com/topic/184967-php-string/#findComment-976427 Share on other sites More sharing options...
Buddski Posted December 13, 2009 Share Posted December 13, 2009 This is a little bit clunky but it will remove all the empty array elements <?php $input = '00:4A:88:66:BB:AA 0Z:8A:44:99:AB:BA 00:00:00:00:00:00:00:e0 00:00:00:00:00:00:00:e0 00:00:00:00:00:00:00:e0'; $i = explode('00:00:00:00:00:00:00:e0',$input); $str = ''; foreach ($i as $value) { $str .= trim($value); } $array = explode(' ',$str); ?> Quote Link to comment https://forums.phpfreaks.com/topic/184967-php-string/#findComment-976428 Share on other sites More sharing options...
canadabeeau Posted December 13, 2009 Author Share Posted December 13, 2009 Okay I have started putting some code together thanks to RussellReal and Buddski. <?php $string = "00:4A:88:66:BB:AA 0Z:8A:44:99:AB:BA 00:00:00:00:00:00:00:e0 00:00:00:00:00:00:00:e0"; $array = explode(' ',str_replace("00:00:00:00:00:00:00:e0","",$string)); ?> Now I need a way of telling how many arrays were/have been made. So in this case $numarrays = 2 but in other cases it may be 5. So can anyone hlp me with this last part of my code. Thanks in advance and to RussellReal and Buddski for their help so far, much appreciated Quote Link to comment https://forums.phpfreaks.com/topic/184967-php-string/#findComment-976430 Share on other sites More sharing options...
Buddski Posted December 13, 2009 Share Posted December 13, 2009 sizeof($arrray); Quote Link to comment https://forums.phpfreaks.com/topic/184967-php-string/#findComment-976431 Share on other sites More sharing options...
canadabeeau Posted December 13, 2009 Author Share Posted December 13, 2009 Okay so ths is what I have <?php $string = "00:4A:88:66:BB:AA 0Z:8A:44:99:AB:BA 00:00:00:00:00:00:00:e0 00:00:00:00:00:00:00:e0"; $array = explode(' ',str_replace("00:00:00:00:00:00:00:e0","",$string)); echo sizeof($array); ?> But it results in "4" when it should be "2" becuase it is counting 00:00:00:00:00:00:00:e0 which I didnt want in the arrays, Thanks again Buddski Quote Link to comment https://forums.phpfreaks.com/topic/184967-php-string/#findComment-976432 Share on other sites More sharing options...
canadabeeau Posted December 13, 2009 Author Share Posted December 13, 2009 This is my new code <?php $input = '00:4A:88:66:BB:AA 0Z:8A:44:99:AB:BA 00:00:00:00:00:00:00:e0 00:00:00:00:00:00:00:e0 00:00:00:00:00:00:00:e0'; $i = explode('00:00:00:00:00:00:00:e0',$input); $str = '';foreach ($i as $value) { $str .= trim($value); } $array = explode(' ',$str); echo sizeof($array); ?> Thankyou to Buddski, whos code I ended up using and to RussellReal for helping. Much appreciated guys, now just got to sort out my other posted issue :-) Quote Link to comment https://forums.phpfreaks.com/topic/184967-php-string/#findComment-976434 Share on other sites More sharing options...
canadabeeau Posted December 13, 2009 Author Share Posted December 13, 2009 THIS IS NOW SOLVED. I AM POST THIS BECUASE I CLICKED "MARK SOLVED" AND I GOT Session verification failed. Please try logging out and back in again, and then try again. SO THIS IS NOW SOLVED. THANKS ALL Quote Link to comment https://forums.phpfreaks.com/topic/184967-php-string/#findComment-976435 Share on other sites More sharing options...
Buddski Posted December 13, 2009 Share Posted December 13, 2009 RussellReal's method wasnt including the 00:00:00:00:00:00:00:e0 it was removing them but leaving unwanted spaces in the string so when it is 'exploded' it creates blank array entries. So '00:4A:88:66:BB:AA 0Z:8A:44:99:AB:BA 00:00:00:00:00:00:00:e0 00:00:00:00:00:00:00:e0 00:00:00:00:00:00:00:e0'; becomes '00:4A:88:66:BB:AA 0Z:8A:44:99:AB:BA '; Quote Link to comment https://forums.phpfreaks.com/topic/184967-php-string/#findComment-976438 Share on other sites More sharing options...
canadabeeau Posted December 13, 2009 Author Share Posted December 13, 2009 I realised that when you gave me the code to calculate the number of $array, which is why I switched to your code, but thanks for the explanation of why Quote Link to comment https://forums.phpfreaks.com/topic/184967-php-string/#findComment-976440 Share on other sites More sharing options...
RussellReal Posted December 13, 2009 Share Posted December 13, 2009 sizeof($arrray); you could also do count() EDIT: and I see good catch buddski Quote Link to comment https://forums.phpfreaks.com/topic/184967-php-string/#findComment-976442 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.