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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

Multiple Break Tags in Search Results


Go to End


4 Posts   1273 Views

Avatar
Lazarus404

Community Member, 72 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, 72 Posts

14 May 2011 at 8:09pm

Anyone have any ideas?

Avatar
martimiz

Forum Moderator, 1391 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, 72 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