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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:37:35+00:00 2026-06-07T05:37:35+00:00

function anchor($text) { return preg_replace(‘#\&gt;\&gt;([0-9]+)#’,'<span class=anchor><a href=#$1>>>$1</a></span>’, $text); } This piece of code is

  • 0
function anchor($text)
{
 return preg_replace('#\&gt;\&gt;([0-9]+)#','<span class=anchor><a href="#$1">>>$1</a></span>', $text);
}

This piece of code is used to render page anchor.
I need to use the

([0-9]+)

part as a variable to do some maths to define the exact url for the href tag.
Thanks.

  • 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-07T05:37:36+00:00Added an answer on June 7, 2026 at 5:37 am

    Use preg_replace_callback instead.

    In php 5.3 +:

    $matches = array();
    $text = preg_replace_callback(
      $pattern,
      function($match) use (&$matches){
        $matches[] = $match[1];
        return '<span class=anchor><a href="#$1">'.$match[1].'</span>';
      }
    );
    

    In php <5.3 :

    global $matches;
    $matches = array();
    $text = preg_replace_callback(
      $pattern,
      create_function('$match','global $matches; $matches[] = $match[1]; return \'<span class=anchor><a href="#$1">\'.$match[1].\'</span>\';')
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's the piece of my HTML code: <li> <a id=section1 href=# onclick=return false>&raquo; Section
In JavaScript, I have the following: function replaceURLWithHTMLLinks(text) { var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig; return
I'm using this code: <script type='text/javascript'> $(document).ready(function () { //Check if url hash value
This function only works once, when I click an anchor element again, nothign happens.
my UI is <li><a href='#'>hello</a></li> anchor tag has already event handler i.e. click(function(){}) I
I am trying to vertical center text in anchor. I used line-height and it
I'm trying to return code like this (can be found here ): {hotspots: [{
Why is this not working? $(document).ready(function(){ var content = '<a href=http://example.com/index.php><b>Some text!</b></a> - <a
I have links like http://example.com?query1=query1&query2=query2 as href of anchor tag. I want to do
Consider the following JS code: <script type=text/javascript> $(function() { // Check if landing on

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.