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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T09:52:14+00:00 2026-05-11T09:52:14+00:00

I have a group of text based rules that are structured like this: Rule

  • 0

I have a group of text based rules that are structured like this:

 Rule 1: Do [XXX] when [PN] greater than [N] Rule 2: Get [PRD ..] and add [X.XX] 

To go with this is an array of data that translates each grouped code into a CSS class ID (for jQuery).

I also have an array of translations from [code] to ID stored in a simple structured array, like the following example:

$translate = array(     'XXX' => 'gen-string-input',      'PN' => 'gen-positivenumber-input',     'N' => 'gen-number-input' ); 

It is important that the following can be achieved:

I need to replace each instance of [code] with a span tag that is structured like this:

<span class='[classname]' unique='[hash]' offset='[offset]'>[CODE]</span> 

This is assuming that the fields are

  • classname is the result of the $translate array
  • hash is an md5 hash that is static for each rule
  • offset is the position of the field in the string (e.g. in the first example, field [XXX] is at position 0, [PN] at position 1 and so on).

Based on this information, I would expect to achieve the following output for Rule 1:

<p>     Do <span class='gen-string-input'               unique='[md5]'              offset='0'>[XXX]</span>     when <span class='gen-positivenumber-input'                unique='[md5]'                 offset='1'>[PN]</span>     greater than <span class='gen-number-input'                         unique='[md5]'                         offset='2'>[N]</span> </p> 

Any help is greatly appreciated, I am currently using str_replace to try and achieve this but it is just not good enough.

  • 1 1 Answer
  • 1 View
  • 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. 2026-05-11T09:52:15+00:00Added an answer on May 11, 2026 at 9:52 am

    Ok, actually what you need is preg_replace_callback. See the recursive callback examples.

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

Sidebar

Related Questions

I have an HTML document where I would like to semantically group text to
I have a group of buttons that should act like toggle buttons, but also
I have an events based table that I would like to produce a query,
I have a form that has a group of 3 text_fields. I need two
I have group of stored procedures with names like 'somename_%'. Are there any way
I have a group of links that I call fancybox on with the arrows
I have a view that displays a group of featured nodes of different categories
So I have a drop-down list and a text-box: <table> <tr> <td>Group Name: </td>
So I have a really simple form on a website that's entirely AJAX based
I have a group of usercontrols that I use multiple instances of through out

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.