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

  • SEARCH
  • Home
  • 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 8666399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:43:18+00:00 2026-06-12T17:43:18+00:00

A while ago I posted this question asking if it’s possible to convert text

  • 0

A while ago I posted this question asking if it’s possible to convert text to HTML links if they match a list of terms from my database.

I have a fairly huge list of terms – around 6000.

The accepted answer on that question was superb, but having never used XPath, I was at a loss when problems started occurring. At one point, after fiddling with code, I somehow managed to add over 40,000 random characters to our database – the majority of which required manual removal. Since then I’ve lost faith in that idea and the more simple PHP solutions simply weren’t efficient enough to deal with the amount of data and the quantity of terms.

My next attempt at a solution is to write a JS script which, once the page has loaded, retrieves the terms and matches them against the text on a page.

This answer has an idea which I’d like to attempt.

I would use AJAX to retrieve the terms from the database, to build an object such as this:

var words = [
    {
        word: 'Something',
        link: 'http://www.something.com'
    },
    {
        word: 'Something Else',
        link: 'http://www.something.com/else'
    }
];

When the object has been built, I’d use this kind of code:

//for each array element
$.each(words,
    function() {
        //store it ("this" is gonna become the dom element in the next function)
        var search = this;
        $('.message').each(
            function() {
                //if it's exactly the same
                if ($(this).text() === search.word) {
                    //do your magic tricks
                    $(this).html('<a href="' + search.link + '">' + search.link + '</a>');
                }
            }
        );
    }
);

Now, at first sight, there is a major issue here: with 6,000 terms, will this code be in any way efficient enough to do what I’m trying to do?.

One option would possibly be to perform some of the overhead within the PHP script that the AJAX communicates with. For instance, I could send the ID of the post and then the PHP script could use SQL statements to retrieve all of the information from the post and match it against all 6,000 terms.. then the return call to the JavaScript could simply be the matching terms, which would significantly reduce the number of matches the above jQuery would make (around 50 at most).

I have no problem with the script taking a few seconds to “load” on the user’s browser, as long as it isn’t impacting their CPU usage or anything like that.

So, two questions in one:

  • Can I make this work?
  • What steps can I take to make it as efficient as possible?

Thanks in advance,

  • 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-12T17:43:19+00:00Added an answer on June 12, 2026 at 5:43 pm

    You can cache the result on insert.

    Basically, when someones insert a new posts, instead of just inserting it into the DB, you run your replace process.

    If your posts are stored like this in the DB

    Table: Posts
    id        post
    102       "Google is a search engine"
    

    You can create another table

    Table: cached_Posts
    id       post_id   date_generated   cached_post                             
    1        102       2012-10-10       <a href="http://google.com">Google</a> is a search engine"
    

    When you retrieve the post, you check if it exists first in the cached_Posts table.

    The reason why you should keep the original is maybe down the road you might add a new keyword to replace. All you will have to do is remake your cache.

    By doing it this way, no client-side JS is required, and you will only have to do it once per post, so your results should come up pretty quick.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is with regard to previous question posted a while ago Remove -1 entry
This is an expansion of a question I posted a while ago: Fitting a
A while ago I asked this question: using xslt stylesheet to convert xhtml blank
I posted this question a while ago regarding where to store non-user specific application
I have posted this question a while ago but got a partial answer to
A while ago, i posted a question about a parent div not reacting to
This is a followup to a question I posted a few days ago. basically,
I'd like to expand a question I posted a while ago : I'm querying
Hello again community, I posted a question just over an hour ago asking for
A few months ago I posted this question because I tried to follow all

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.