0

Hi ,
I am creating a search page where searching from databaes against a field .From the string "Birdnesting is the common hobby with the English boys.And boys are playing in the ground .Again the boys are playing in the ground. But Birdnesting is not a cake . " if I enter "Birdnesting is the common hobby" will display the above highlighted strings . I mean to say first (.)period /dot to last (.)period/dot of the searched strings.

Thanks in advance

Subrata

4
Contributors
3
Replies
18
Views
3 Years
Discussion Span
Last Post by flashhtml5
0

Something like this may work:

if (strpos($str, 'StringHere') !== FALSE)
    echo 'Found it';
else
    echo "nope!";

Answer was found here.

Edited by Begginnerdev

0

The SQL will need to change or you would need to process
the result with PHP.

For the SQL solution, explore the SUBSTRING_INDEX() function:

query .= "SELECT SUBSTRING_INDEX('" . $searchString . "', '.', 2)";

For the post-processing PHP solution, try preg_match() or one of the above suggested fixes:

  $searchPattern = '/\.\s+$searchString\./'; // This will need to be
                                            // modified to suit 
                                            // your needs.
  preg_match($searchPattern, $queryResult, $finalMatch); 

Regards,
Shawn

Edited by flashhtml5: typo

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.