Jump to content

string comparison in php


sudhakararaog

Recommended Posts

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.

 

Link to comment
https://forums.phpfreaks.com/topic/114634-string-comparison-in-php/
Share on other sites

Try this it works.

 

<?php

$string = 'your search string';

$content = file_get_contents("test.html");

// The "i" after the pattern delimiter indicates a case-insensitive search

if (preg_match("/$string/i", "$content")) {

  echo "A match was found.";

} else {

  echo "A match was not found.";

}

 

?>

 

Regards,

Suresh

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.