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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:35:15+00:00 2026-06-02T00:35:15+00:00

I have the following string Enter Contarct Fields wherever you want and enclose it

  • 0

I have the following string

“Enter Contarct Fields wherever you want and enclose it with {}.You can use field’s id or field’s fieldcode for example {25} or {FIELD_CONTRACTTEXT}”

I want to replace this {25} and {FIELD_CONTRACTTEXT} with their equivalent value from databse.
Say 25 is a ID so I wanted to put name of the field of which 25 is the ID of.

There are many examples of replacing curly braces but no solution is there for replacing content like this. Please help me, I have tried many things.

PS: Please keep in mind that occurrence of {} is dynamic and 25 will not be a static number and there can be multiple {} in a string.

  • 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-02T00:35:17+00:00Added an answer on June 2, 2026 at 12:35 am

    You can use preg_match_all() to find the occurrences, use this array to find the values in the database and then str_replace to replace each value after that.

    To begin with you will need to fetch all the occurrences:

    preg_match_all('/{(.*?)}/', $string, $matches, PREG_PATTERN_ORDER);
    

    The matches array will look like this:

    Array
    (
        [0] => Array
            (
                [0] => {}
                [1] => {25}
                [2] => {FIELD_CONTRACTTEXT}
            )
    
        [1] => Array
            (
                [0] => 
                [1] => 25
                [2] => FIELD_CONTRACTTEXT
            )
    
    )
    

    You can then cylce through the array to find the individual elements that need to be replaced.

    You can use the following to check the database and then replace values:

    mysql_connect("localhost", "root", "");
    mysql_select_db("data");
    
    $string = "Enter Contarct Fields wherever you want and enclose it with {}.You can use field's id or field's fieldcode for example {25} or {FIELD_CONTRACTTEXT}";
    
    preg_match_all('/{(.*?)}/', $string, $matches, PREG_PATTERN_ORDER);
    
    foreach($matches[1] as $match) {
        $sql = mysql_query("SELECT * FROM table WHERE `element`='".addslashes($match)."'");
        if(mysql_num_rows($sql)==1){
            $row = mysql_fetch_assoc($sql);
            str_replace($string, "{".$match."}", $row['value']);
        }
    }
    
    echo $string; //echos final output with replaced values
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code example below. Whereby you can enter a command to
I have the following code: BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in)); System.out.print(Enter: ); String
I have following string: Test, User < test@test.com >, Another, Test < another@test.com >,
I have following situation: String a = A Web crawler is a computer program
I have the following string arrays: var myArray1 = new string[] {A, B, C};
I have the following: string test = CustomerNumber; or string test2 = CustomerNumberHello; the
I have the following string: <?xml version=1.0 encoding=utf-8?> <string xmlns=http://tempuri.org/UKash/Service1><UKashTransaction><txCode>99</txCode><txDescription>Failed</txDescription><settleAmount> <settleAmount><transactionId>1341481253EDFC871620</transactionId><changeIssueVoucherNumber> <changeIssueVoucherNumber><changeIssueVoucherCurr> <changeIssueVoucherCurr><changeIssueAmount> <changeIssueAmount><changeIssueExpiryDate>
I have the following string as a variable: var name1 = '001-C6AL7_deepgreen_C3AE7_tankhakinavy_FJAG7_blackredmulti_FBAE7_tanbrown.jpg'; Which is
I have the following string assigned to a variable: $date = 16 June, 2012,
I have the following string repeated many times (about 10 times) <br /> <a

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.