Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8966175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:58:10+00:00 2026-06-15T16:58:10+00:00

I have keyword bolding function here: $ignore = array (‘div’, ‘class’, ‘high’, ‘light’, ‘highlight’);

  • 0

I have keyword “bolding” function here:

$ignore = array ('div', 'class', 'high', 'light', 'highlight');
$keywords = explode(' ', $qsvarus);
$title[$key] = preg_replace('/'.implode('|', $keywords).'/i', '<b>$0</b>', $title[$key]);
$infoo[$key] = preg_replace('/'.implode('|', $keywords).'/i', '<b>$0</b>', $infoo[$key]);

The problem is it sometimes catches some of my html tags. How to tell it to ignore everything shorter than 3 letters and certain specific words from $ignore array when <b></b> $keywords?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T16:58:11+00:00Added an answer on June 15, 2026 at 4:58 pm

    I would simply loop around the keywords array first, removing any matches in the ignore array (use in_array) and also any keywords that are 3 characters or less.

    Then if you want to make sure you are not in a tag, the following should suffice:

    /\b(keyword|keyword|keyword)\b(?![^<]*[>])/
    

    I’ve basically appended a negative lookahead:

    (?![^<]*[>])
    

    The regex will match as long as that look ahead for a closing html > not preceded by an opening tag < doesn’t match. I you do get a closing tag, you should be able* to assume that you are inside a tag.

    Putting that back into the preg_replace:

    preg_replace('/\b('.implode('|', $keywords).')\b(?![^<]*[>])/i', '<b>$1</b>', $subject);
    
    • This does assume that there isn’t an unencoded greater than (>)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the models: class Article(models.Model): title = models.TextField(blank=True) keywords = models.ManyToManyField(Keyword, null=True, blank=True)
I have created a keyword search in SQL that takes a list of keywords
I have the following relatonships Keyword(1)<--->(n)K2I(n)<--->(1)Clip(n)<--->(1)Media Namely, We have a set a keywords and
I have a function that accepts wildcard keyword parameters: def func(**kargs): doA doB How
I have code like this: function search_keyword(){ $keyword = $this->db->escape_like_str(trim($_POST['keyword'])); $sql = ( SELECT
I have code like this: function search_keyword(){ $keyword = trim($_POST['keyword']); $search_explode = explode( ,
I have code like this: function search_keyword(){ $keyword = trim($_POST['keyword']); $search_explode = explode( ,
I have a keyword field of type Array that is generated on the creation
Does the object keyword have any uses except for classes like: class HelloWorld(object): pass
Is this even possible? Here's the problem: I have a keyword search with this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.