Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 25th, 2006, 5:30 AM   #1
ktsirig
Programmer
 
Join Date: Oct 2005
Posts: 54
Rep Power: 3 ktsirig is on a distinguished road
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...
ktsirig is offline   Reply With Quote
Old Apr 25th, 2006, 9:16 AM   #2
Lich
Professional Programmer
 
Lich's Avatar
 
Join Date: May 2005
Location: Detroit
Posts: 254
Rep Power: 4 Lich is on a distinguished road
Send a message via AIM to Lich Send a message via MSN to Lich
if($var1 == $var2)
{
do something
} else {
do something else
}
__________________
--John Cruz
Web Developer
www.cruzweb.net
Lich is offline   Reply With Quote
Old Apr 25th, 2006, 9:45 AM   #3
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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
DaWei is offline   Reply With Quote
Old Apr 25th, 2006, 1:03 PM   #4
Lich
Professional Programmer
 
Lich's Avatar
 
Join Date: May 2005
Location: Detroit
Posts: 254
Rep Power: 4 Lich is on a distinguished road
Send a message via AIM to Lich Send a message via MSN to Lich
pregmatch or something i'm assuming
__________________
--John Cruz
Web Developer
www.cruzweb.net
Lich is offline   Reply With Quote
Old Apr 25th, 2006, 4:02 PM   #5
JavaMan
Newbie
 
Join Date: Oct 2005
Posts: 29
Rep Power: 0 JavaMan is on a distinguished road
Either substr or preg_match.
JavaMan is offline   Reply With Quote
Old Apr 25th, 2006, 5:13 PM   #6
mrynit
Hobbyist Programmer
 
mrynit's Avatar
 
Join Date: Mar 2006
Location: olympia,WA
Posts: 332
Rep Power: 3 mrynit is on a distinguished road
Send a message via AIM to mrynit Send a message via MSN to mrynit Send a message via Yahoo to mrynit Send a message via Skype™ to mrynit
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.
mrynit is offline   Reply With Quote
Old Apr 25th, 2006, 7:46 PM   #7
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
@ 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
DaWei is offline   Reply With Quote
Old Apr 26th, 2006, 1:00 AM   #8
mrynit
Hobbyist Programmer
 
mrynit's Avatar
 
Join Date: Mar 2006
Location: olympia,WA
Posts: 332
Rep Power: 3 mrynit is on a distinguished road
Send a message via AIM to mrynit Send a message via MSN to mrynit Send a message via Yahoo to mrynit Send a message via Skype™ to mrynit
silly as in it is over kill for the problem?
mrynit is offline   Reply With Quote
Old Apr 26th, 2006, 1:31 AM   #9
Jimbo
Battle Programmer
 
Jimbo's Avatar
 
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 748
Rep Power: 3 Jimbo is on a distinguished road
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?
Jimbo is offline   Reply With Quote
Old Apr 26th, 2006, 3:45 AM   #10
mrynit
Hobbyist Programmer
 
mrynit's Avatar
 
Join Date: Mar 2006
Location: olympia,WA
Posts: 332
Rep Power: 3 mrynit is on a distinguished road
Send a message via AIM to mrynit Send a message via MSN to mrynit Send a message via Yahoo to mrynit Send a message via Skype™ to mrynit
Quote:
Originally Posted by Jimbo
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?
binary tree is faster than just going from start to finish(the teacher said that). you can make the bin tree sreach better if you want.

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.
mrynit is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 6:09 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC