Forum Moderators: coopster

Message Too Old, No Replies

match entire pattern against a string?

         

ktsirig

10:16 am on Apr 25, 2006 (gmt 0)

10+ Year Member



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...

hakre

11:41 am on Apr 25, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



what function are you using to match these variables with each other?

ktsirig

12:39 pm on Apr 25, 2006 (gmt 0)

10+ Year Member



Hi hakre, thanx for your time...
A fellow from another forum helped me out with the code, so I am posting it in case it's useful to anyone :

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

// this will give you back a positive result because var1 includes var2
$pos = strpos ($var1, $var2);
if ($pos === false) // Note use of '==='
echo "string not found<br>";
else
echo "string found, beginning at position <b>".$pos."</b><br>";

//this will give back FALSE because var2 is not into var3
$pos = strpos ($var3, $var2);
if ($pos === false) // Note use of '==='
echo "string not found";
else
echo "string found, beginning at position <b>".$pos."</b><br>";

?>