473,800 Members | 2,614 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is there any function in php that will match a word exactly and if it finds it, it returns true.

Hi,

Is there any function in php that will match a word exactly and if it
finds it, it returns true.

For example if I search for "CA"

strVar = "Bob is from Los Angeles CA" - return true

strVar "Bob is from Canada" -- returns false

Any help is appreciated

Thanks

-Ross

Nov 10 '07 #1
12 2675
In our last episode,
<11************ **********@c30g 2000hsa.googleg roups.com>,
the lovely and talented ro*********@gma il.com
broadcast on comp.lang.php:
Hi,
Is there any function in php that will match a word exactly and if it
finds it, it returns true.

Yes.
--
Lars Eighner <http://larseighner.com/ <http://myspace.com/larseighner>
Countdown: 436 days to go.
What do you do when you're debranded?
Nov 10 '07 #2
<comp.lang.ph p>
<>
<Sat, 10 Nov 2007 13:09:14 -0800>
<11************ **********@c30g 2000hsa.googleg roups.com>
Is there any function in php that will match a word exactly and if it
finds it, it returns true.

For example if I search for "CA"

strVar = "Bob is from Los Angeles CA" - return true

strVar "Bob is from Canada" -- returns false
$demo="Bob is from Los Angeles CA";

$qaz="CA";

$wsx=strpos($qa z,$demo);

if ($wsx==true) {print "exact match found";}

NOTE: untested and you may need to play around with it .
Nov 10 '07 #3
Thanks for your response. But if in your example
strVar "Bob is from Canada" -- would return true when I want it to
return false.

Nov 10 '07 #4
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

ro*********@gma il.com wrote:
Thanks for your response. But if in your example
strVar "Bob is from Canada" -- would return true when I want it to
return false.
*borrowing Krustov's code as template*

$demo="Bob is from Los Angeles CA";

$qaz=" CA"; // note the extra space

$wsx=strpos($qa z,$demo);

if ($wsx==true) {print "exact match found";}
- --
Brendan Gillatt
brendan {at} brendangillatt {dot} co {dot} uk
http://www.brendangillatt.co.uk
PGP Key: http://pgp.mit.edu:11371/pks/lookup?...rch=0xBACD7433
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (MingW32)

iD8DBQFHNjP4kA9 dCbrNdDMRAnQ9AJ 0dL6C23gPRQ4n40 hjqIXg+H5nEQwCg 0Yum
r9nv+WwcsnZfQIC 22bQCdlU=
=uQxP
-----END PGP SIGNATURE-----
Nov 10 '07 #5
<comp.lang.ph p>
<Brendan Gillatt>
<Sat, 10 Nov 2007 22:43:04 +0000>
<uu************ *************** ***@pipex.net>
*borrowing Krustov's code as template*

$demo="Bob is from Los Angeles CA";

$qaz=" CA"; // note the extra space

$wsx=strpos($qa z,$demo);

if ($wsx==true) {print "exact match found";}
Thats not a ideal solution to the well known php bug you refer to .

Best not to mention such things until a user has a problem IMHO .
Nov 10 '07 #6
On Nov 10, 5:51 pm, Krustov <m...@privacy.n etwrote:
<comp.lang.ph p>
<Brendan Gillatt>
<Sat, 10 Nov 2007 22:43:04 +0000>
<uu-dnYh9Kt09rqvanZ 2dnUVZ8sLin...@ pipex.net>
*borrowing Krustov's code as template*
$demo="Bob is from Los Angeles CA";
$qaz=" CA"; // note the extra space
$wsx=strpos($qa z,$demo);
if ($wsx==true) {print "exact match found";}

Thats not a ideal solution to the well known php bug you refer to .

Best not to mention such things until a user has a problem IMHO .
And which well known bug is that?

Nov 11 '07 #7
On Nov 11, 5:37 am, Krustov <m...@privacy.n etwrote:
<comp.lang.ph p>
<>
<Sat, 10 Nov 2007 13:09:14 -0800>
<1194728954.083 106.150...@c30g 2000hsa.googleg roups.com>
Is there any function in php that will match a word exactly and if it
finds it, it returns true.
For example if I search for "CA"
strVar = "Bob is from Los Angeles CA" - return true
strVar "Bob is from Canada" -- returns false

$demo="Bob is from Los Angeles CA";

$qaz="CA";

$wsx=strpos($qa z,$demo);

if ($wsx==true) {print "exact match found";}

NOTE: untested and you may need to play around with it .
using strpos, this would also match

$demo="Bob is from Los Angeles CAblahblah";

while i think OP wanted exact match. Correct me if i am wrong.

maybe something like this:

$demo="Bob is from Los Angeles CA ddfs";
$s = split(" ",$demo);
foreach ($s as $k)
{
if( $k === "CA" )
{
echo "Found CA: $k\n";
}
}

Nov 11 '07 #8
This might work.

<?php
function myfunc($string, $pattern)
{
if(strpos(' '.$string.' ', ' '.$pattern.' ') !== FALSE)
{
return true;
}
return false;
}

var_dump(myfunc ('Bob is from Los Angeles CA','CA'));
var_dump(myfunc ('Bob is from Canada','CA'));
?>

On Nov 10, 4:09 pm, ross.one...@gma il.com wrote:
Hi,

Is there any function in php that will match a word exactly and if it
finds it, it returns true.

For example if I search for "CA"

strVar = "Bob is from Los Angeles CA" - return true

strVar "Bob is from Canada" -- returns false

Any help is appreciated

Thanks

-Ross

Nov 11 '07 #9
On Nov 10, 3:09 pm, ross.one...@gma il.com wrote:
Hi,

Is there any function in php that will match a word exactly and if it
finds it, it returns true.

For example if I search for "CA"

strVar = "Bob is from Los Angeles CA" - return true

strVar "Bob is from Canada" -- returns false

Any help is appreciated

Thanks

-Ross
You might use preg_match() with word boundaries... perhaps?

Nov 11 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
4967
by: Penn Markham | last post by:
Hello all, I am writing a script where I need to use the system() function to call htpasswd. I can do this just fine on the command line...works great (see attached file, test.php). When my webserver runs that part of the script (see attached file, snippet.php), though, it doesn't go through. I don't get an error message or anything...it just returns a "1" (whereas it should return a "0") as far as I can tell. I have read the PHP...
5
6565
by: Richard A. DeVenezia | last post by:
Hi: function foo () { var xyz = 123; function bar () { var abc = 456; } } I can alert (foo) to see the function source
6
2684
by: Ryan Muller | last post by:
My company just upgraded from Access 97 to Access 2003 today and we are having some issues in a database that generates a Word document from information selected in a form. Here is the code we were using without issue previous to the switch: 'Start Word and create a new doc from the template Set objWord = CreateObject("Word.Basic") objWord.AppMaximize "Microsoft Word", 1 objWord.FileNew Template:=StrTemplPath & "letter.dot"
3
3660
by: Beta What | last post by:
Hello, I have a question about casting a function pointer. Say I want to make a generic module (say some ADT implementation) that requires a function pointer from the 'actual/other modules' that takes arguments of type (void *) because the ADT must be able to deal with any type of data. In my actual code, I will code the function to take arguments of their real types, then when I pass this pointer through an interface function, I...
3
2028
by: Russell | last post by:
Hey, ok i have numerous tables to search through for a 'site search'. some of the searchble fields have html embeded within so after some quick referencing, saw I can use the regExp function to strip out all the HTML leaving only the raw text. (done and works a treat) My issue is:
4
1455
by: hanseymoon | last post by:
Dear newsgroup: I've got this long function, which works good overall to spell check words from a dictionary and I am not in a position to replace it. Can someone please see where or how it might be chopping up words like: don't. It brings them back as: 't, chopping off the "don" before the apostrophe. I've looked over the whole situation and ran many $string tests....and it appears to be narrowed it down to this. I may be wrong and...
18
1786
Dököll
by: Dököll | last post by:
Here it goes again, thanks again for responding: 'PROPOSED SOLUTION 2 'I wanted to not creatre a file and just read straight out of Text6.Text and 'output my findings in legal text boxes 'I also needed/had to, because OF LACK OF EXPERIENCE, figure out wheter my finding was true first 'before out putting, thus Text1.Text = Text6.SelLength = Len(strGetWords) was born 'when true, Text2.Text = strGetWords 'Here is the problem, I searched...
6
3536
by: lawrence k | last post by:
Wierd. Go to this page: http://www.ihanuman.com/search.php and search for "yoga" This query gets run: SELECT * FROM albums WHERE MATCH(name,description) AGAINST ('yoga') ORDER BY id DESC
6
3117
by: Andrus | last post by:
I need to implement vfp function which uses * and ? wildcards: static bool Like( cExpression1, cExpression2) cExpression1 Specifies the character expression that Like( ) compares with cExpression2. cExpression1 can contain the wildcards such as * and ?. The question mark (?) matches any single character in cExpression2 and the asterisk (*) matches any number of characters. You can mix any number of wildcards in any
0
10507
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10255
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7582
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6815
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5473
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5607
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4150
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3765
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2948
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.