Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/184967-php-string/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/184967-php-string/#findComment-976428
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/184967-php-string/#findComment-976430
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/184967-php-string/#findComment-976432
Share on other sites

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 :-)

Link to comment
https://forums.phpfreaks.com/topic/184967-php-string/#findComment-976434
Share on other sites

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  ';

Link to comment
https://forums.phpfreaks.com/topic/184967-php-string/#findComment-976438
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.