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

Something like this may work:

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

Answer was found here.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.