Re: [PHP] string comparison

2008-07-13 Thread Robert Cummings
On Sun, 2008-07-13 at 21:47 +0530, Sudhakar wrote:
 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.

I don't suggest using file_get_contents. It would probably be more
efficient (at least less memory intensive) to use fopen() and fread().
Just be sure you overlap each read by $the_size_of_the_largest
phrase_or_keyword - 1. Then use stripos() for matching... of course that
won't work so well if whitespace doesn't need to match exactly in
phrases. In which case you'll need to resort to other techniques.

Cheers,
Rob.
-- 
http://www.interjinn.com
Application and Templating Framework for PHP


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] string comparison

2008-07-13 Thread dg


On Jul 13, 2008, at 9:17 AM, Sudhakar wrote:


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.


I use this script to list archive files from a directory based on  
keyword.  I'd guess a modified version using the keywords from users  
might work:


// create archives box
if ($handle = opendir('../diaryarchives/')) {
while (false !== ($file = 
readdir($handle))) {
$pos = strpos($file, diary_);
$pagemarked = diary._;
if ($pos !== false) {
//print $filebr;
$file_name = ereg_replace 
($pagemarked,,$file);
$file_name = ereg_replace 
(.php,,$file_name);
//print * $file_namebr;
//print $filebr;
			$archive_list_gather[] = 'lia href=/diaryarchives/'. 
$file.''.$file_name.'/a/li';

}
}
closedir($handle);
}
rsort($archive_list_gather);
foreach($archive_list_gather as $value) {
$archive_list .= $value;
}
// build archives box
$archives_box = 'div id=diary-archives
h3 class=sideimg src=/images/h3s_diaryarchives.gif  
alt=Diary Archives width=225 height=20 //h3

ul
'.$archive_list.'
/ul
/div';

// publish archives box
$filename = PATHA.'/diaryarchivesbox.php';
publishpages($archives_box, $filename);


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] string comparison

2002-07-27 Thread John Holmes

Strcmp() is case sensitive. So use it when you need a case sensitive
comparison.

---John Holmes...

 -Original Message-
 From: Bas Jobsen [mailto:[EMAIL PROTECTED]]
 Sent: Saturday, July 27, 2002 12:35 PM
 To: PHP General
 Subject: [PHP] string comparison
 
 Hello,
 
 When should i prefer strcmp() above == or !=?
 I have test it out (see code below).
 But a == comparison seems to be faster always.
 First i thought is was cause, if(strcmp($1,$2)!=0),
 needs two comparisons (strcmp and !=). But even
 if($1!=$2) is faster then if(strcmp($1,$2)).
 
 Thanks,
 
 Bas Jobsen
 
 ?
 
 function getmicrotime(){
 list($usec, $sec) = explode( ,microtime());
 return ((float)$usec + (float)$sec);
 }
 
 
 $t1='hello';
 $t2='hello';
 $t3='hallo';
 
 ?
 1000x:?
 $start=getmicrotime();
 for($a=0; $a10; $a++) if(strcmp($t1,$t3));//nonmatch
 echo getmicrotime()-$start;
 ?
 br
 1000x:?
 $start=getmicrotime();
 for($a=0; $a10; $a++) if($t1!=$t3);//nonmatch
 echo getmicrotime()-$start;
 ?
 
 br
 1000x:?
 $start=getmicrotime();
 for($a=0; $a10; $a++) if(!strcmp($t1,$t3));//match
 echo getmicrotime()-$start;
 ?
 br
 1000x:?
 $start=getmicrotime();
 for($a=0; $a10; $a++) if($t1==$t3);//match
 echo getmicrotime()-$start;
 ?
 br
 
 1000x:?
 $start=getmicrotime();
 for($a=0; $a10; $a++) if(strcmp($t1,$t2));//nonmatch
 echo getmicrotime()-$start;
 ?
 br
 1000x:?
 $start=getmicrotime();
 for($a=0; $a10; $a++) if($t1!=$t2);//nonmatch
 echo getmicrotime()-$start;
 ?
 
 br
 1000x:?
 $start=getmicrotime();
 for($a=0; $a10; $a++) if(!strcmp($t1,$t2));//match
 echo getmicrotime()-$start;
 ?
 br
 1000x:?
 $start=getmicrotime();
 for($a=0; $a10; $a++) if($t1==$t2);//match
 echo getmicrotime()-$start;
 ?
 br
 
 
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] String Comparison

2001-07-24 Thread Jason Bell

oh wait.. I just realize my goof  it is treating it like I want to
divide image by pjpeg.  LMAO

*sigh*  I guess I should just go home while I'm ahead.  haha

-Jason


- Original Message -
From: Jason Bell [EMAIL PROTECTED]
To: PHP Users [EMAIL PROTECTED]
Sent: Tuesday, July 24, 2001 3:59 PM
Subject: [PHP] String Comparison


Hello.

I'm trying to compare two strings, and performa function if the are the
same.  Easy right?  I thought so until I tried it...

$query = select type from images where id=$id;
$result = mysql_query($query);
$type = mysql_result($result,0,type);
print $type;
if (image/pjpeg == $type) { print Type is JPG; };

returned:

image/pjpeg
Warning: Division by zero in /home/daelic/www/photo/mkthumb.php on line 8


Any idea on why this won't work?

Thanks!

Jason



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] String Comparison

2001-07-24 Thread Phil Driscoll

On Tuesday 24 July 2001 23:59, Jason Bell wrote:

 if (image/pjpeg == $type) { print Type is JPG; };

you need to put image/jpeg in quotes.
Ideally you would also do a safer string comparison than ==
eg if(!strcmp('image/jpeg',$type))
-- 
Phil Driscoll

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]