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 6655205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:29:18+00:00 2026-05-26T01:29:18+00:00

I am using preg_replace for buzzword type functionality, using a list of buzzwords, searching

  • 0

I am using preg_replace for buzzword type functionality, using a list of buzzwords, searching for them in an article and then using preg_replace to wrap a link around them.

My buzzwords are:

Online Marketing
Social Media Markeing
Social Media
Social
Brand Marketing
Brand
Search Engine Optimisation
SEO
Email Marketing
Email
Twitter
Facebook
LinkedIn

and I am doing my preg_replace like this…

$text = preg_replace("/Online Marketing/", "<a href='".$base."online-marketing/'>Online Marketing</a>", $text);

but the issue is I am having to do a preg_replace for each possible variation like so…

$text = preg_replace("/Online Marketing/", "<a href='".$base."online-marketing/'>Online Marketing</a>", $text);
$text = preg_replace("/Online marketing/", "<a href='".$base."online-marketing/'>Online marketing</a>", $text);
$text = preg_replace("/online marketing/", "<a href='".$base."online-marketing/'>online marketing</a>", $text);

Which is extremely long winded, now I know that I can use an array with str_repalce like this:

$from = array("Online Marketing", "Online marketing", "online marketing");
$name = str_replace($from, "", $text);

But I cannot see a way of finding which part of the array was matched and then replacing it with the correct link, as you can see the str_replace above just totally deletes my buzzword, its just an example.

So I was wondering if anyone would be able to help me find a way of using an array of buzzwords in a str_replace or preg_replace but also make sure that it repalces the buzzword with the correct link.

Hope someone can help

  • 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-05-26T01:29:19+00:00Added an answer on May 26, 2026 at 1:29 am

    I took a mixture of all of your answers and this is my finished result…

    $Fbuzzwords = array(" online marketing", " social media marketing", " social-media-marketing", " social media", 
                    " social", " brand marketing", " brand", " search engine optimisation", " seo", " email marketing", 
                    " email", " e-mail marketing", " e-mail", " tiwtter", " facebook", " linkedin");
    
    $Ubuzzwords = array("online-marketing", "social-media-marketing", "social-media-marketing", "social-media-marketing", 
                    "social-media-marketing", "brand-marketing", "brand-marketing", "search-engine-optimisation", 
                    "search-engine-optimisation", "online-marketing", "online-marketing", "online-marketing", 
                    "online-marketing", "social-media-marketing", "social-media-marketing", "social-media-marketing");
    
    $i = 0;
    
    foreach ($Fbuzzwords as $buzzword)
    {
        $url = $Ubuzzwords[$i];
    
        $Rbuzzwords = array(" <a href='".$base.$url."/'>online marketing</a>", " <a href='"
    .$base.$url."/'>social media marketing</a>", 
                    " <a href='".$base.$url."/'>social-media-marketing</a>", " <a href='".$base.$url."/'>social media</a>", 
                    " <a href='".$base.$url."/'>social</a>", " <a href='".$base.$url."/'>brand marketing</a>", 
                    " <a href='".$base.$url."/'>brand</a>", " <a href='".$base.$url."/'>search engine optimisation</a>", 
                    " <a href='".$base.$url."/'>seo</a>", " <a href='".$base.$url."/'>email marketing</a>", 
                    " <a href='".$base.$url."/'>email</a>", " <a href='".$base.$url."/'>e-mail marketing</a>", 
                    " <a href='".$base.$url."/'>e-mail</a>", " <a href='".$base.$url."/'>tiwtter</a>", 
                    " <a href='".$base.$url."/'>facebook</a>", " <a href='".$base.$url."/'>linkedin</a>");
    
        $replacement = $Rbuzzwords[$i];
    
        $text = preg_replace("/$buzzword/i", "$replacement", $text);
    
        $i++;
    }
    

    So I have 3 arrays, 1 for finding the word on the page, and 2 for the url, I loop though all of the text for each part of the array making sure I catch every case

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

Sidebar

Related Questions

I am using preg_replace to add a link to keywords if they are found
I'm looping through a list of words being replaced using preg_replace. Here is the
I'm using preg_replace to create urls for modrewrite based paging links. I use: $nextURL
I'm trying to minify multiple CSS files using preg_replace() . Actually, I'm only trying
I am having an issue removing %3Cbr+%2F%3E from my string using the preg_replace function.
Using online interfaces to a version control system is a nice way to have
When using preg_replace() in PHP with strings generated at runtime, one can protect special
I'm trying to match tags using preg_replace. The regex used is: <video[^>]*>(.*?)</video> But I'm
I'd like to replace the string {{edit(3)}} with open3close using preg_replace
How can I replace &Aring; with some other string using preg_replace? Thanks!

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.