Search the Community
Showing results for tags 'intersect'.
-
Hi, simply put; I am having a very difficult time trying to find a way I can Match (partial?) strings, comparing to 2 arrays (the matches have different [Keys].) for example: $abs="Bob Rob Sue"; $abt="sometext Bob1:2 moretext Sue3:4 othertext Rob5:6 etc"; how can I put into code, when "Bob1:2" is used, it finds a match of "Bob", and assigns the complete string of "Bob1:2" ? The course I have been trying I get Bob, Rob, and Sue.. but the #numbers# are in the wrong place. ie; it will result with "Sue5:6" I understand its a [key] issue, using array_intersect along with some explodes/implodes has helped get me this far.. but i am stumped. Someway of matching the two arrays coreectly (or keys) would be what i need to figure out. Heres is what i have now: Thank you for any help, at all. cheers. <?php $abs="Bob Rob Sue"; $abby="sometext Bob1:2 is Sue3:4 where Rob2:1 etc"; $nums = preg_replace('/[a-zA-Z]/', ' ', $abby); $lets = preg_replace('/[0-9]:?[^0-9]/', ' ', $abby); //$lets1=array_intersect($abs, $lets); $absArr = explode(' ', $abs); $abbyArr = explode(' ', $lets); $letsx=array_intersect($absArr, $abbyArr); //echo $letsx[0] . "</br>"; //############################################# $nums1='/(\d+\:\d+)/s'; preg_match_all($nums1, $nums, $nums2); foreach($nums2 as $numsx){ } $abi0="$letsx[0]+$numsx[0]"; $abi1="$letsx[1]+$numsx[1]"; $abi2="$letsx[2]+$numsx[2]"; $answer=$abi0."</br>".$abi1."</br>".$abi2."</br>"; echo $answer; ?> current results: Bob+1:2 Rob+3:4 Sue+2:1 My desire is that it would Result in: Bob+1:2 Sue+3:4 Rob+2:1 The #nums are obviously correct. but the #letters (words/names) obviously are not the same "[key]". I hope that this is doable.. Thanks in advance.