verdrm Posted August 4, 2010 Share Posted August 4, 2010 I have two strings: $string = shell_exec('reg.bat '.$arg); //returns word\0word\0word $stringA = "$string"; $stringB = "word,other,word2,other2"; $array1 = explode('\0', $stringA); $array2 = explode(',', $stringB); $result = array_diff($array1, $array2); I can use array_diff to find the differences, but the last word in $array1 shows up as not in both strings even though it is because of the \0 delimiter. How can I include the last word as well? Link to comment https://forums.phpfreaks.com/topic/209791-array_diff/ Share on other sites More sharing options...
radar Posted August 4, 2010 Share Posted August 4, 2010 perhaps you should add another line $stringA = preg_replace("\0", ',', $stringA); $array1 = explode(',', $stringA); $array2 = explode(',', $stringB); Link to comment https://forums.phpfreaks.com/topic/209791-array_diff/#findComment-1095107 Share on other sites More sharing options...
verdrm Posted August 4, 2010 Author Share Posted August 4, 2010 That didn't work. Another suggestion? Link to comment https://forums.phpfreaks.com/topic/209791-array_diff/#findComment-1095113 Share on other sites More sharing options...
radar Posted August 4, 2010 Share Posted August 4, 2010 hmmm have you echo'd done a print_r on both the $array1 and array2? to see that they are what you need them to be. echo "<pre>"; print_r('ARRAY 1: '.$array1); print_r('<br>ARRAY 2: '.$array2); echo "</pre>"; Link to comment https://forums.phpfreaks.com/topic/209791-array_diff/#findComment-1095123 Share on other sites More sharing options...
PFMaBiSmAd Posted August 4, 2010 Share Posted August 4, 2010 You likely have some other character, such as a space or a \r or \n as part of the data. You should use trim() on each element of the array via the array_map function. Link to comment https://forums.phpfreaks.com/topic/209791-array_diff/#findComment-1095126 Share on other sites More sharing options...
verdrm Posted August 4, 2010 Author Share Posted August 4, 2010 Would you provide a code example of how to do that? Link to comment https://forums.phpfreaks.com/topic/209791-array_diff/#findComment-1095135 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.