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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:34:20+00:00 2026-05-14T21:34:20+00:00

I have a Joomla plugin (not important in this context), which is designed to

  • 0

I have a Joomla plugin (not important in this context), which is designed to take an input with a load of numbers (within a paragraph of text) and replace them with a series of s.

My problem is that I need to do a preg_replace on my $article->text, but I don’t know how to then apply the changes to the matched terms. I’ve seen the preg_replace_callback, but I don’t know how I can call that within a function.

function onPrepareContent( &$article, &$params, $limitstart )
    {
        global $mainframe;
        // define the regular expression
        $pattern = "#{lotterynumbers}(.*?){/lotterynumbers}#s";
        if(isset($article->text)){
            preg_match($pattern, $article->text, $matches);
            $numbers = explode("," , $matches[1]);
            foreach ($numbers as $number) {
                echo "<div class='number'><span>" . $number . "</span></div>";  
            }
        }else{
            $article->text = 'No numbers';
        }
        return true;
    }

AMENDED CODE:

function onPrepareContent( &$article, &$params, $limitstart )
    {
        global $mainframe;
        // define the regular expression
        $pattern = "#{lotterynumbers}(.*?){/lotterynumbers}#s";
        if(isset($article->text)){
            preg_match($pattern, $article->text, $matches);
            $numbers = explode("," , $matches[1]);
            foreach ($numbers as $number) {
                $numberlist[] = "<div class='number'><span>" . $number . "</span></div>";   
            }
            $numberlist = implode("", $numberlist);
            $article->text = preg_replace($pattern, $numberlist, $article->text);

        }else{
            $article->text = 'No numbers';
        }
        return true;
    }
  • 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-14T21:34:21+00:00Added an answer on May 14, 2026 at 9:34 pm
    function onPrepareContent( &$article, &$params, $limitstart )
    {
        global $mainframe;
        // define the regular expression
        $pattern = "#{lotterynumbers}(.*?){/lotterynumbers}#s";
        if(isset($article->text)){
            $article->text=preg_replace_callback($pattern,create_function('$match','$init="<div class=\'number\'><span>";$out="</span></div>"; return $init.implode($out.$init,explode(",",$match[1])).$out;'),$article->text);
    
        }else{
            $article->text = 'No numbers';
        }
        return true;
    }
    

    I’ve not tested it but it should work

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

Sidebar

Ask A Question

Stats

  • Questions 514k
  • Answers 514k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Unfortunately it's not possible using the wp_list_pages() function to add… May 16, 2026 at 6:18 pm
  • Editorial Team
    Editorial Team added an answer Write a script in “Adobe ExtendScript Toolkit” (or any other… May 16, 2026 at 6:18 pm
  • Editorial Team
    Editorial Team added an answer Use register variables for parameters and locals. Of course, depending… May 16, 2026 at 6:18 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Do we have a Joomla component which can zip many components and install them?
I have a GWT application which I would like to run from within a
I have done some research on this subject, and found out, that Gzipping and
I dont know much about joomla but I have a problem. I started reading
We have to develop an Ecommerce site with 20+ pages of static content which
I'm very new to Joomla. I have a question about components/modules. I'm doing the
I have an asp.net application which is purely build using C#, CSS, Javascript. Now
I really have read the other articles that cover this subject. But I seem
I am new to joomla, and I was wondering if somebody could recommend me
I have followed these instructions at Balupton to the word but I cannot seem

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.