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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T03:01:59+00:00 2026-06-05T03:01:59+00:00

ok I have this following code for replacing a certain parts of the a

  • 0

ok I have this following code for replacing a certain parts of the a big string to something

     $string = 'this <task>post</task> was a <post>post item</post> 
before but now this is now a <task>task item</task> 
and will become like <task>this one</task>';

         $pattern = '^<task>*</task>$';
         $datainmiddle = preg_replace($pattern, $replacement, $string);
         $replacement = strlen(datainmid);
         //I have no idea what to do next...(ノД`)・゜・。

now the thing I want to do here is the following

  1. I want to grab each substring in the string that starts with <task> and ends with </task>
  2. With each substring I grabbed, I want to grab every data in the middle of the <task> and </task>
  3. In every data i grabbed in the middle of the markups I want to measure their length using strlen
  4. Now I want to replace every substring that starts with <task> and ends with </task> with the length of their strings in their middles.

the output must be like this

this 4 was a 9 before but now this is now a 9 and will become like 8

If you found it confusing. Please tell it to me

  • 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-05T03:02:01+00:00Added an answer on June 5, 2026 at 3:02 am

    Okay, easy enough:

    preg_replace('#<task>(.*?)</task>#e', "strlen('\\1')", $str);
    

    The regex uses (.*?) to start a memory pattern which I later use to pass into strlen().

    I’m using .*? to indicate a non-greedy match (otherwise it matches everything between the first <task> and last occurrence of </task>.

    The e modifier is used to evaluate the second parameter to preg_replace; this makes it possible to write '\\1' in the expression before it gets evaluated as a whole to return the string length.

    Hope that explanation helps a bit to understand the solution.

    • 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: $('#select_albums').load(document.location.href + &action=get_albums); But this is only replacing only
I have this following code, here CssClass is of the String type. <asp:Panel ID=Panel1
I have this following jquery text fly-in animation.Here is my code before I explain
I have the following code (in this case for two images - but in
I have the following code to do this, but how can I do it
hello i have following code and it works fine for finding and replacing string...
I have this following code which will return all the current semesters. How do
Never thought I'd have this problem :) The following snippet of code works in
I have the following code: Parallel.ForEach(this.listView2.CheckedItems, new ParallelOptions { MaxDegreeOfParallelism = 4 }, (CheckedItem)
I have following code for alertdialog: AlertDialog.Builder helpBuilder = new AlertDialog.Builder(this); helpBuilder.setTitle(Options); helpBuilder.setMessage(Choose Your

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.