lostprophetpunk Posted September 2, 2009 Share Posted September 2, 2009 I was wondering if you can use an array in the strpos() function, such as... $array = array(1,2,3,4,5,6); $pos = strpos($array, $text); I am trying to find any of the characters in the string, inside the array. If there is a way...how would I go about it? Thanks in advance. Quote Link to comment Share on other sites More sharing options...
trq Posted September 2, 2009 Share Posted September 2, 2009 As stated in the manual the second argument accepts a mix of types. Quote Link to comment Share on other sites More sharing options...
lostprophetpunk Posted September 2, 2009 Author Share Posted September 2, 2009 As stated in the manual the second argument accepts a mix of types. That didn't really help at all...as it was the wrong function. I have looked up the function I am using but I cannot figure it out. I want to try and get the string position of any of the characters in the array. I am going about it the wrong way? Quote Link to comment Share on other sites More sharing options...
trq Posted September 2, 2009 Share Posted September 2, 2009 Sorry, I completely misread your post. Wouldn't really make any sense with strstr either. Assuming you have an array of chars (not numbers) you could easily create a loop to do what you want. $a = array('a','g','h'); $s = 'the dog and cat'; foreach ($a as $v) { $pos = strpos($s, $v); if ($pos === false) { echo "$v not found in $s\n"; } else { echo "$v found at position $pos\n"; } } Quote Link to comment Share on other sites More sharing options...
ILMV Posted September 2, 2009 Share Posted September 2, 2009 lostprophetpunk, do you mean that you want to return the array position? You could use something like...array_search, which will return the array key based on a search. Quote Link to comment 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.