Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
string comparison in php
Old 07-14-2008, 04:29 AM string comparison in php
Ultra Talker

Posts: 254
Trades: 0
hi

i am writing a small application where a user enters a phrase in the textfield and i would like to display all the files present in the root directory which consists of the keyword or keywords entered by the user.

i have used a few comparison functions but i am not getting the expected result.

$my_file = file_get_contents("filename.html");
what ever the user enters whether it is a single word or few words i would like to compare with $my_file in a case insensitive manner.

can anyone suggest the best method and how to go about.

thanks.
sudhakararaog is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-14-2008, 05:12 AM Re: string comparison in php
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
With stripos, you can find them.
http://www.php.net/manual/en/function.stripos.php

PHP Code:
$my_file file_get_contents("filename.html");
if(
stripos($my_file,$keyword)!==false){
  echo 
"Keyword found";
}
else{
  echo 
"keyword not found";

__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 07-14-2008, 06:03 AM Re: string comparison in php
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
preg_match
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 07-20-2008, 03:52 AM Re: string comparison in php
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
Quote:
Originally Posted by priyakochin View Post
pattern matching is better for url and all.
You just wanted to increase your comments counter or what?
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 07-22-2008, 08:23 AM Re: string comparison in php
abhi's Avatar
Super Talker

Posts: 100
Name: abhishek
Location: mauritius
Trades: 0
sorry for my curiosity but is what you are asking for is a search engine thing.
__________________

Please login or register to view this content. Registration is FREE
Visit Mauritius Island for your holidays!
Please login or register to view this content. Registration is FREE
abhi is offline
Reply With Quote
View Public Profile Visit abhi's homepage!
 
Old 07-22-2008, 02:43 PM Re: string comparison in php
Super Talker

Posts: 116
Trades: 0
if they input multiple words, split it up into an array using explode() and then you could also use strcmp, however i think that it might need an exact match for that...
__________________


Please login or register to view this content. Registration is FREE

nasaboy007 is offline
Reply With Quote
View Public Profile Visit nasaboy007's homepage!
 
Old 07-26-2008, 07:28 AM Re: string comparison in php
Junior Talker

Posts: 2
Trades: 0
The strncmp() function compares two strings.
This function returns:
  • 0 - if the two strings are equal
  • <0 - if string1 is less than string2
  • >0 - if string1 is greater than string2
strncmp(string1,string2,length)
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE
Aran is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to string comparison in php
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.29946 seconds with 12 queries