Searching for a long string within a string

Discussion in 'PHP' started by Phil_S, Jan 25, 2012.

  1. #1
    Hi Guys

    I'm having a problem to find the string "Lecter in ‘The Silence of The Lambs’ (1991), Anthony Hopkins’ diverse roles" on a web page where this does actually exist. (by the way, it's just an example that contains ', (,) for example, the actual text can be different.)

    Using:

    if (strpos($ch,$test) !== false)
    return $valid;
    else
    return !$valid;

    where $ch is a string of the page source, and $test is "Lecter in ‘The Silence of The Lambs’ (1991), Anthony Hopkins’ diverse roles" , it returns $valid.

    However, if I look for ( using $test is "Lecer in ‘The Silence of The Lambs’ (1991), Anthony Hopkins’ diverse roles") which has the 't' in Lecter missing, which doesn't appear on the page, it still returns true, ie $valid. Any ideas as to where I'm going wrong please?

    The string isn't at the start of the page, so it's not an issue with starting position = 0.

    I've a feeling it's to do with needing to escape the ' characters, as well as the ' and ‘ ones?

    Phil
     
    Phil_S, Jan 25, 2012 IP