Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jun 2009
    Thanked 0 Times in 0 Posts

    does anyone know a function i could use instead of stristr

    I have an array with the following elements

    PHP Code:
    define("LIST_OF_SCHOOLS""st patricks,Piarsaigh,Phiarsaigh,St Vincents,Glanmire,Farranree,North Presentation,north mon,north monestrey,Scoil iosagain,St aidans,knocknaheeny,mon"); 
    PHP Code:
    $schoolList explode(','LIST_OF_SCHOOLS); 
    PHP Code:
    function checkForSchool($page$schoolList) {
    preg_match('%(Studied at|Went to|Goes to) \\\u003ca href=\\\\"http:\\\/\\\/www.facebook.com\\\/pages\\\/[a-zA-Z-]*\\\/\d*\\\\" data-hovercard=\\\\"\\\/ajax\\\/hovercard\\\/page.php\?[a-zA-Z=0-9]*\\\\">([a-zA-Z\s]*)\\\u003c\\\/a>%'$page$match);
    $match && count($match)>0) {
    $cnt=0$cnt<count($schoolList); $cnt++) {
    $school trim($schoolList[$cnt]);
    $school!="" && stristr($match[2], $school)) { 
    blue($match[2].": Match for school found");
    red("No school set on profile");
    How come my function is returning true for this match

    mond Community High School
    Inveralmond Community High School: Match for school found

    I only want it too return true if all the match corresponds with one of the element in the array $schoolList

  2. #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Saskatoon, Saskatchewan
    Thanked 2,668 Times in 2,637 Posts
    You can use an in_array to make a comparison: in_array($match[2], $schoolList), just throw it in a branch condition. Don't need to iterate it or anything.
    I don't see any purpose of your define though, the string isn't exactly ideal to work with. Just a simple array declaration would make a lot more sense, or you can read it in from a text file or something to make it easier using fgetcsv or something like that.

    To answer your question, your last case is 'mon'. That matches Inveralmonnd, which is why you get the result. If you are looking for an identical comparison, you need to use str[case]cmp instead (for which you will need to pay attention to datatypes for the return).
    If you are looking for things that *begin* with these list of schools, use the strpos function instead and ensure it returns identical to 0 (=== 0) in order to find it as the first needle in the string.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  3. Users who have thanked Fou-Lu for this post:

    kevinkhan (02-21-2011)


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts