![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: Oct 2005
Posts: 54
Rep Power: 4
![]() |
match entire string in PHP
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... |
|
|
|
|
|
#2 |
|
Professional Programmer
|
if($var1 == $var2)
{ do something } else { do something else } |
|
|
|
|
|
#3 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
How WERE you checking? Just curious.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#4 |
|
Professional Programmer
|
pregmatch or something i'm assuming
|
|
|
|
|
|
#5 |
|
Newbie
Join Date: Oct 2005
Posts: 29
Rep Power: 0
![]() |
Either substr or preg_match.
|
|
|
|
|
|
#6 |
|
Hobbyist Programmer
|
check the length of each var, if they are not the same length then the content is not the same(completely identical). if they are the same do a recursive binary tree search to check the indavidual characters. if they all match then the vars are identical. <- can you do that in PHP? i did that in C++. it's the same idea.
|
|
|
|
|
|
#7 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
@ mrynit: Your idea is functional, but silly. The OP got his answer, I was just curious as to how he was failing, before.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#8 |
|
Hobbyist Programmer
|
silly as in it is over kill for the problem?
|
|
|
|
|
|
#9 |
|
Battle Programmer
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 770
Rep Power: 3
![]() |
Why would you use a binary tree per say, instead of just iterating through the elements and checking them linearly? And even bettery, why not use an optimized library function?
|
|
|
|
|
|
#10 | |
|
Hobbyist Programmer
|
Quote:
recursion > iteration ? library function would work. if you want to do it your self then do what i said. thats what first came to mind for doing such a check. |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|