Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing Highlights #2

Open
briansuda opened this issue Mar 13, 2015 · 1 comment
Open

Missing Highlights #2

briansuda opened this issue Mar 13, 2015 · 1 comment

Comments

@briansuda
Copy link
Owner

There is an issue with the same search term listed consecutively, every other terms is highlighted.

This is an issue with the Regular Expressions NEEDING atleast some sort of whitespace or non-letter
character on both sides of the term. When two terms are consecutive the first term "eats" the white-
space before and after the term, therefore the second term does NOT have a white-space char
before it any longer.

The simple fix is to not require the REGEX to need that white-space buffer, but then it will find word
matches inside of words. So a further testing is needed to fix this issue.

@briansuda
Copy link
Owner Author

An alternative (and simpler) regex/replacement could be:

preg_replace(
    '/(?<=^|\W)('.preg_quote($q,'/').')(?=\W|$)/iu',
    "<span class=\"hl$colour\">\$1</span>",
    $tag_matches[3][$i]
)

Note that this only matches standalone words ("q=nana" doesn't highlight "banana"), works on consecutive matches, works at the start and end of strings, and doesn't require adding spaces anywhere.

Also note this still breaks if the search term starts/ends with non-word characters. For example, if the search term is ".", the string "..." would be mangled (the first dot would not be highlighted, but the second two would.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant