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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:13:23+00:00 2026-06-15T20:13:23+00:00

I have a block of content with people’s names in double brackets. For example:

  • 0

I have a block of content with people’s names in double brackets. For example:

Lorem ipsum dolor sit amet, consectetur [[Jane Doe]] adipisicing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
enim ad minim veniam, quis nostrud exercitation ullamco [[John Doe]]
laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
pariatur. Excepteur sint occaecat cupidatat non proident, [[Susan
Van-Something]] sunt in culpa qui officia deserunt mollit anim id est
laborum.

I am trying to write a regular expression that takes the names out of the double brackets and replaces them in the content with a link following the formatting below:

<a href='http://www.example.com/jane-doe/'>Jane Doe</a>

In the URL the spaces are transformed into hyphens and the entire name is lowercased.

So far i have

// the filter function
function names_brackets( $content ) {
    // regex replace the names with links
    // return the content
    return preg_replace_callback( "/^([[[A-Za-z0-9- ]+?]])/" , "names_callback" , $content);
}

// callback function to allow post processing
function names_callback ( $matches ) {
    $find = array(' ', '[', ']');
    $replace = array('-', '', '');
    return '<a href="http://www.example.com/' . strtolower( str_replace($find, $replace, $matches[1]) ) . '">' . str_replace(']', '', str_replace('[', '', $matches[1])) . '</a>';
}

Unfortunately I suspect that there is something wrong with the regular expression. Any help would be appreciated.

  • 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-15T20:13:24+00:00Added an answer on June 15, 2026 at 8:13 pm

    You do need to escape your brackets in the pattern, but there’s still room for improvement: you actually don’t have to do another search-and-replace within the callback function, if you use several capture groups. Like here:

    function names_brackets( $content ) {
        return preg_replace_callback('/(\[\[)([\w -]+?)(]])/',
                   'names_callback', $content);
    }
    
    function names_callback ( $matches ) {
        return '<a href="http://www.example.com/' 
               . strtolower(str_replace(' ', '-', $matches[2])) 
               . "\">$matches[2]</a>";
    }
    

    This way both opening and closing brackets will still be cut out from the result, but the callback function won’t even have to know about them: it only uses the second group – the one with the name.

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

Sidebar

Related Questions

In my page i have a block of content where i want to display
I have a requirement that in a webpage I have multiple block of content
I am trying to have a content block always be shown to the user,
I have 3 content type HTML HTML4 HTML5 2 menu block HTML4 HTML5 In
I have the following code block, as the content of my AppDelegate.h of an
Let's say I have cleaner like this .cleaner:after { content: '.'; display: block; clear:
I have the following code on my page: <p align=justify style=font-size:10pt;display:block;height:200px;vertical-align:middle;> Content </p> I
I have blocks of content that are toggled on/off via jQuery and I want
I have a block of HTML code that contains a button <button class=someButton onclick=openPage('test')></button>
I'm a drupal newbie (mean it :) I have a Block, created with View

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.