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? Quote 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); Quote 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? Quote 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>"; Quote 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. Quote 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? Quote Link to comment https://forums.phpfreaks.com/topic/209791-array_diff/#findComment-1095135 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.