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

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer What about: private string SQLVersion() { string version = "";… May 13, 2026 at 12:54 pm
  • Editorial Team
    Editorial Team added an answer Iterate backwards, if you can: for x in range(subjectlength -… May 13, 2026 at 12:54 pm
  • Editorial Team
    Editorial Team added an answer See Disk Point Picking. You generate a random theta (0… May 13, 2026 at 12:54 pm

Related Questions

Looking for a scalable, flexible and fast database design for 'Build your own form'
I've been programming for a long time now, but I'm not the world's most
I have a mvc view made up of a matrix of radio buttons. Each
I'm working on making an ASCII based game, and everywhere I look people are

Trending Tags

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

Top Members

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.