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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:48:39+00:00 2026-05-13T21:48:39+00:00

The routine below does two scans over an input stream of hypertext. The first

  • 0

The routine below does two scans over an input stream of hypertext. The first pass is a spin replacement on user defined phrase options. The second pass is a find replace on the tags collection in the doReplace function below.

I’m just looking for suggestions on how it might be optimized. I’m having no performance issues as is. But I want to build for scalability.

/* FIND REPLACE SPIN
--------------------------------------------------------------------*/
function doReplace($content)
{
// content is a precompiled text document formatted with html and 
// special using replacement tags matching the $tags array collection below
    $tags = array('[blog-name]', '[blog-url]', '[blog-email]');
    $replacements = array('value1', 'value2', 'value3');
    $content = str_replace($tags, $replacements, $content);
    return $content;
}

function doSpin($content) {
// the content also has phrase option tags denoted by [%phrase1|phrase2_|phrase3%]
// delimiters throughout the text.
  return preg_replace_callback('!\[%(.*?)%\]!', 'pick_one', $content);
}

function pick_one($matches) {
  $choices = explode('|', $matches[1]);
  return $choices[rand(0, count($choices)-1)];
}

$my_source_page = file_get_contents('path/to/source';}
$my_source1_spin = doSpin($my_source_page);
$my_source1_replace = doReplace($my_source1_spin);
$my_source1_final = addslashes($my_source1_replace);

//Now do something with $my_source1_final
  • 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-13T21:48:40+00:00Added an answer on May 13, 2026 at 9:48 pm

    To be honest, I don’t see anything wrong with the code you’ve posted. The main bottleneck in the code is likely going to be the file_get_contents call.

    The only thing I can see myself is that you’re allocating the string to different variables (four variables beginning $my_source) which will use more memory than if you just used 1 or 2 variables.

    But unless you’re reading a large amount of text into memory very frequently on a busy site, then I don’t think you need to worry about the code you’ve posted. And you said yourself, you’re not having any performance issues at the moment 😉

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

Sidebar

Related Questions

I'm writing a password encryption routine. I've written the below app to illustrate my
How would I handle something like the below uri using ASP.NET MVC's routing capability:
Routine maintenance on a website often involves verifying that links are valid, flagging bad
I have a little routine that's run under Linux and Windows written in C
Part of the setup routine for the product I'm working on installs a database
I'm writing a routine that validates data before inserting it into a database, and
I have this routine that calculates the seconds-to-date for a struct tm . On
I have a javascript routine that is performing actions on a group of checkboxes,
Has anyone written an 'UnFormat' routine for Delphi? What I'm imagining is the inverse
Do you have a simple debounce routine handy to deal with a single switch

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.