0

I want to use the function search_excerpt() to generate excerpts. Unfortunately this function is returning exactly same text as I submit. For example I tried this:

$test = (search_excerpt('test', 'this is a test'));
print $test;

This is returning "this is a test".

I was expecting more something like:

"this is a test"

What is wrong in my code?

2

Try this code.I have just added a space after the string and this will surely work

$string = 'this is a test';   
$test = (search_excerpt('test', $string.' '));
print $test;

In the search_excerpt() if the search text is the last one, then preg_replace omits the search text.In order to overcome this I just added a empty space to the string.

// Highlight keywords. Must be done at once to prevent conflicts ('strong' and '<strong>').
  $text = preg_replace('/' . $boundary . '(' . implode('|', $keys) . ')' . $boundary . '/iu', '<strong>\0</strong>', $text);
  • 1
    This definitely works – Clive Feb 17 '15 at 11:07
0

Normal behaviour for this function, see the documentation: https://api.drupal.org/api/drupal/modules!search!search.module/function/search_excerpt/7

Try this code:

$test = (search_excerpt('test', 'this is a test'));
print '"'.$test.'"';
  • 1
    That doesn't seem to make any difference - maybe because of the what Ram is indicating in the other answer? – Clive Feb 17 '15 at 11:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.