Forum Moderators: coopster

Message Too Old, No Replies

"Is Within" function?

compare variable agains know number of possibilities

         

neophyte

6:13 am on Sep 13, 2004 (gmt 0)

10+ Year Member



Does anyone remember Hypercard?

I use to use it alot way, way back when. It had a function called (if I'm remembering correctly) Is Within, where you could pass the function stringA and stringB and it would see if stringA was found "within" stirngB.

I know I could do the same with an array and a while loop but wanted to know if there was already an internal function for such needs.

I've searched php.net's function list and, while it came up with a lot of string-related functions, nothing that I could see matched what I need.

All I want to do is pass a single variable (which might contain, say, "4") which would then be compared against and a string of comma-delimited ints (i.e.: 3,4,7,9,4). If the number passed was found in the list of ints, it would simply return TRUE; if not FALSE.

So, is there a prebuilt function like this one?

Thanks.

Neophyte

RonPK

7:38 am on Sep 13, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Not that I know of. in_array() comes close.

mincklerstraat

8:34 am on Sep 13, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Or add something to each side of your 'needle' int to make it unique -
$uniqueint = '-'.$int.'-';
and (if ($strpos($commaseparatedlist, $uniqueint)!== 0)){}

notice the!== - not!= - checks for type as well as value, which you need with $strpos.

I like the array idea of the poster above better though.

neophyte

12:24 pm on Sep 13, 2004 (gmt 0)

10+ Year Member



Thanks to you both for your replies. I looked at in_array at php.net and that look like it might do the deal.

My wife, however, has been hollering at me to come to dinner for the past hour ("You're always at the <snipped> computer!") so I better let this go right now before she gets the shotgun.

I'll let you guys know if it worked for me tomorrow.

Neophyte

[edited by: coopster at 12:35 pm (utc) on Sep. 13, 2004]
[edit reason] Language TOS 3, 14 [webmasterworld.com] [/edit]