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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:51:12+00:00 2026-05-14T03:51:12+00:00

I have a paragraph of text and i want to replace some words using

  • 0

I have a paragraph of text and i want to replace some words using PHP (preg_replace). Here’s a sample piece of text:

This lesson addresses rhyming [one]words and ways[/one] that students may learn to identify these words. Topics include learning that rhyming words sound alike and these sounds all come from the [two]ending of the words[/two]. This can be accomplished by having students repeat sets of rhyming words so that they can say them and hear them. The students will also participate in a variety of rhyming word activities. In order to demonstrate mastery the students will listen to [three]sets of words[/three] and tell the teacher if the words rhyme or not.

If you notice there are many occurances of the word ‘words’. I want to replace all the occurances that don’t occur inside any of the tags with the word ‘birds’. So it looks like this:

This lesson addresses rhyming [one]words and ways[/one] that students may learn to identify these birds. Topics include learning that rhyming birds sound alike and these sounds all come from the [two]ending of the words[/two]. This can be accomplished by having students repeat sets of rhyming birds so that they can say them and hear them. The students will also participate in a variety of rhyming word activities. In order to demonstrate mastery the students will listen to [three]sets of words[/three] and tell the teacher if the birds rhyme or not.

Would you use regular expressions to accomplish this?
Can a regular expression accomplish this?

  • 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-14T03:51:12+00:00Added an answer on May 14, 2026 at 3:51 am

    The tags you have don’t define a regular language and thus regular expressions won’t work well for this. The best I think you can do is remove all the tags (replace them with something else), replace “words” with “birds” and then put the content back.

    $str = preg_replace_callback('!\[one\].*?\[/one\]!s', 'hash_one', $input);
    $str = str_replace('words', 'birds', $str);
    $output = preg_replace_callback('!:=%\w+%=:!', 'replace_one', $str);
    
    $hash = array();
    
    function hash_one($matches) {
      global $hash;
      $key = ':=%' . md5($matches[0]) . '%=:'; // to ensure this doesn't occur naturally
      $hash[$key] = $matches[0];
      return $key;
    }
    
    function replace_one($amtches) {
      global $hash;
      $ret = $hash[$matches[0]];
      return $ret ? $ret : $matches[0];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a paragraph of text below that I want to use an input
I have a database full of text fields that look like this: (paragraph of
I have some text, something like this: Paragraphs of text (SOME KNOWN TEXT)Unknown Text(SOME
I have long text . And I'm converting this string to dict. Here is
Here's my quandary. I have a variable that contains a paragraph of text, and
I have a paragraph of text, sitting in a p -tag. Inside this text,
I have multiple texts fields every field is paragraph of text and I want
I have paragraph like below. I just Want to ignore text [[drama film|film]] .Output
I have a paragraph of text and when a button is clicked I want
I have this schema: Story _id name Paragraph _id text story_id ( the chapter

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.