match entire string PHP

Discussion in 'PHP' started by ktsirig, Apr 25, 2006.

  1. #1
    Hi all!
    What I want to ask might be rather silly, but I have come across it a couple of days now and don't seem to find any solution.
    Consider the following variables :

    $var1= "ps :Hello and welcome to greece";
    $var2= "ps :Hello and";
    $var3= "ps :It was nice to meeting you";

    My problem is that, when I check $var2, it matches both $var1 and $var3, because , as you can see, $var3 has "ps" in it.
    So, I was wondering if there is a way of matching ENTIRE $var2 and not just portions of it. In this way, it would match only $var1 and not $var3...
     
    ktsirig, Apr 25, 2006 IP
  2. mad4

    mad4 Peon

    Messages:
    6,986
    Likes Received:
    493
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Are you doing the matching in an SQL query or just in php?

    Can you post some of your code?
     
    mad4, Apr 25, 2006 IP
  3. ktsirig

    ktsirig Peon

    Messages:
    22
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hi mad4, thanx for your time...

    A fellow from another forum suggested :

    if (false !== strpos ($var1, $var2)) {
    // match ok : $var2 is in $var1
    }

    which worked fine for me... I guess strpos was what I needed...
    PS: No sql, just php I am writing at the time being...
     
    ktsirig, Apr 25, 2006 IP
  4. drewbe121212

    drewbe121212 Well-Known Member

    Messages:
    733
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    125
    #4
    If you need to get specific with the matching as well, dont forget our friend eregi and Regular expressions.
     
    drewbe121212, Apr 26, 2006 IP