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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:32:47+00:00 2026-05-24T09:32:47+00:00

I want to replace the words(excluding: , ; . stc.) with links. How can

  • 0

I want to replace the words(excluding: , ; . stc.) with links. How can I do this?

<?php
$string = "wordey; string, boom";
$string = preg_replace("/[^a-z]/i", "<a href='x'>/[^a-z]/i</a>", $string); //??
echo $string; // <a href='wordey'>wordey</a>; <a href='string'>string</a>, <a href='boom'>boom</a>
?>

Please note that the ; , . – etc are important.

  • 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-24T09:32:49+00:00Added an answer on May 24, 2026 at 9:32 am

    Neither your regular expression or the replacement string make sense. The regular expression is matching everything not in the range [a-z] (denoted by the leading ^), and your replacement string appears to contain regular expression syntax, which it shouldn’t.

    If you’re trying to replace the words, your regular expression should probably look something like /[a-z]+/i which does a case-insensitive greedy match for one or more letters.

    To use the matched string in the replacement, you can use \N, where N is a number indicating the sub-match you want to reference. To add a sub-match, place brackets around the part of the regular expression you’re interested in referencing. The regex becomes /([a-z]+)/i.

    Put them together and you get the following, which appears to give the output you’re looking for.

    $string = preg_replace("/([a-z]+)/i", "<a href='\\1'>\\1</a>", $string);
    

    Note the double-backslash is an escape sequence inserting a literal backslash into the string.

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

Sidebar

Related Questions

How can I replace some words in a string with some other words? For
I want to replace all threeletter words with new string. MsgBox display variable threeLetterWord
I have string asdf-zxcv-qwer- and I want to replace all occurence of words between
eg. I want to replace instances of some words with their string length XXXX
I have several php files in directory, I want to replace a few words
Suppose I have a string like this: abc%\%%%% I want to replace multiple %%%
I want to replace specific words (laptop, asus, acer) with links (test.com/l12, test.com/13, test.com/14)
I want to replace parts of a string that contains the following words $%word$%
I have a filter bad words codes below I want to replace this ARRAY
Want to replace some words on the fly on my website. $content = preg_replace('/\bWord\b/i',

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.