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. Link to comment https://forums.phpfreaks.com/topic/172814-strpos/ 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. Link to comment https://forums.phpfreaks.com/topic/172814-strpos/#findComment-910835 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? Link to comment https://forums.phpfreaks.com/topic/172814-strpos/#findComment-910858 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"; } } Link to comment https://forums.phpfreaks.com/topic/172814-strpos/#findComment-910868 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. Link to comment https://forums.phpfreaks.com/topic/172814-strpos/#findComment-910872 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.