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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:30:33+00:00 2026-06-12T05:30:33+00:00

How can I make this filter work on multiple matches within the same text?

  • 0

How can I make this filter work on multiple matches within the same text?

function _embed_link($text, $filter, $format) {
  if (preg_match_all("/\[(.*?)\|(node|term)\:(\d+)\]/i", $text, $params)) {
    foreach ($params[0] as $key => $param) {
      $args = array(
        $params[0][$key],
        $params[1][$key],
        $params[2][$key],
        $params[3][$key],
      );
      $markup = _embed_link_process($args);
      $text = preg_replace("/\[(.*?)\|(node|term)\:(\d+)\]/", $markup, $text, 1);
    }
  }

  return $text;
}

and this is the function which returns the link

function _embed_link_process($params = array()) {
  $output = '';

  if ($params[2] == 'node') {
    // Find node by it's id
    $node = node_load($params[3]);
    $output .= render(l($params[1], 'node/'. $node->nid, array(
      'attributes' => array(
        'class' => array('embed-link', 'embed-link-node', 'embed-link-node-'. $node->nid),
      ),
    )));
  }

  if ($params[2] == 'term') {
    $term = taxonomy_term_load($params[3]);;
    $output .= render(l($params[1], 'taxonomy/term/'. $term->tid, array(
      'attributes' => array(
        'class' => array('embed-link', 'embed-link-term', 'embed-link-term-'. $term->tid),
      ),
    )));
  }

  return $output;
}

Example text using the filter:

Ut [Click here|node:4] enim ad minim veniam, quis [Click here|term:42]
nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit
esse cillum [Click here|term:1] dolore eu fugiat nulla pariatur.
Excepteur sint occaecat cupidatat non proident, sunt in culpa [Click
here|node:42] qui officia deserunt mollit anim id est laborum.

The goal is to have each […] replaced by the proper link.

  • 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-12T05:30:34+00:00Added an answer on June 12, 2026 at 5:30 am

    Modifying function _embed_link to use preg_match_all

    function _embed_link($text, $filter, $format) {
      if (preg_match_all("/\[(.*?)\|(node|term)\:(\d+)\]/i", $text, $params)) {
        foreach ($params[0] as $key => $param) {
          // $param => [Click here|node:4]
          $param_arr  = array (
            $params[0][$key], // [Click here|node:4]
            $params[1][$key], // Click here
            $params[2][$key], // node
            $params[3][$key], // 4
          );
          $markup = _embed_link_process($param_arr);
          $text = str_replace($param, $markup, $text);
        }
      }
    
      return $text;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make a cgridview that can filter data from relations table. This
How can I make this code work? #!/bin/bash ARRAYNAME='FRUITS' FRUITS=( APPLE BANANA ORANGE )
How can I make this second struct work, when the first struct has a
How can I make this input transparent? <input type=text class=foo> I've tried this but
How can I make this code work? class Meta @array = [:a,:b] def self.method_missing(name,
I am trying very hard to make this work but I can't see what
I am trying to make this ajax request function work but netbeans is giving
How i can make this condition en VB.NET If e.KeyCode = [a-zA-Z0-9] Then 'Blah
How can I make this print properly without using two printf calls? char* second
How can I make this sliding panel example to slide down on mouseover and

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.