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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T22:10:46+00:00 2026-06-02T22:10:46+00:00

Sounds simple enough, but I’m feeling quite stupid today. If I have an array

  • 0

Sounds simple enough, but I’m feeling quite stupid today.

If I have an array like this:

$defined_vars = array(
    '{POST_TITLE}' => $item['post']['name'], 
    '{POST_LINK}' => $item['post']['link'], 
    '{TOPIC_TITLE}' => $item['topic']['name'], 
    '{TOPIC_LINK}' => $item['topic']['link'], 
    '{MEMBERNAME}' => $txt['by'] . ' <strong>' . $item['membername'] . '</strong>', 
    '{POST_TIME}' => $item['time'], 
    '{VIEWS}' => $txt['attach_viewed'] . ' ' . $item['file']['downloads'] . ' ' . $txt['attach_times'],
    '{FILENAME}' => $item['file']['name'],
    '{FILENAME_LINK}' => '<a href="' . $item['file']['href'] . '">' . $item['file']['name'] . '</a>',
    '{FILESIZE}' => $item['file']['size'],
    '{DIMENSIONS}' => $item['file']['image']['width'] 'x' $item['file']['image']['height'],
);

And a String like this:

$string = '<div class="largetext centertext">{POST_LINK}</div><div class="smalltext centertext">{MEMBERNAME}</div><div class="floatright smalltext dp_paddingright">{POST_TIME}</div><div class="dp_paddingleft smalltext">{VIEWS}</div>';

I need it to be replaced with the values of those keys. Is that possible to do? Perhaps using str_replace() somehow? Are array keys allowed to have curly brackets within them? Would that cause any problems? Also, I need this to replace the $string value for ALL times these are found, cause it is possible to have the same output desired more than 1 time. For example, if {POST_TITLE} is defined twice it should output the value twice exactly where they have used it at within the string.

Thanks

  • 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-02T22:10:47+00:00Added an answer on June 2, 2026 at 10:10 pm
    foreach($defined_vars as $key=>$value) {
      $string = str_replace($key,$value,$string);
    }
    

    this is using str_replace like you asked and it is easy to see what is happening. Php also has the strtr or string translate function to do pretty much just this so you could also use

    $string = strtr($string,$defined_vars);
    

    but would have to remember what that function does.

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

Sidebar

Related Questions

This sounds like a simple enough question, but can't find the answer for the
This sounds simple enough, but so far I have been unable to solve it.
This sounds like a really simple question, but I am new to PHP. If
Unfortunately, the answer to this question isn't quite as simple as it sounds... but
Sounds simple enough...but I've been plugging away at this, trying to find the one
This sounds simple enough but I haven't been able to figure out how to
Sounds simple enough, but its not working. In this example, I want to set
This sounds simple but my regex knowledge is limited. I need an expression to
This sounds like a why would you do that? sort of question, but here
I'm trying to set the text of a TextView which sounds simple enough but

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.