Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Multiple Break Tags in Search Results


Reply


4 Posts   1023 Views

Avatar
Lazarus404

Community Member, 71 Posts

11 May 2011 at 11:59pm

Hi all,

In my current SilverStripe project, I'm using the search features to return content items from the site pages. These items have images, which the search strips out, which is good. However, where the images were, I'm left with multiple <br /> tags, so the results is shown with large gaps. Is there an easy way to remove extra break tags or perhaps compress them to a single break?

Thanks,
Lee

Avatar
Lazarus404

Community Member, 71 Posts

14 May 2011 at 8:09pm

Anyone have any ideas?

Avatar
martimiz

Forum Moderator, 1132 Posts

15 May 2011 at 5:58am

Maybe something like this simple testcase will help (I'm no regexpert):

$searchResult = 'aaaaaa<br />bbbbbbbb<br /><br />cccc';

$pattern = '@(<br( /)*\>)+@i';

$replacement = ''; //or use $replacement = '<br />';

searchResult = preg_replace($pattern, $replacement, $searchResult);

Avatar
Lazarus404

Community Member, 71 Posts

16 May 2011 at 9:34pm

Thank you. I was hoping there would be a simple method I could override or a switch of some sort. There's obviously a method somewhere that strips out the images, so there must be a way to hijack that so that the output could be massaged.

Lee