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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T07:21:31+00:00 2026-05-20T07:21:31+00:00

I need to remove the content between those html blocks: $var1 = <html><head> <meta

  • 0

I need to remove the content between those html blocks:

$var1 ="

    <html><head>
    <meta http-equiv='content-type' content='text/html; charset=ISO-8859-1'></head><body>
    <img alt='shopozilla' src='http://www.ssopte.com/images/2010/usdos-logo-seal.png' >

    <span style='font-family: Arial,Helvetica,sans-serif; color: rgb(93, 93, 93);
    font-size: 17px; font-weight: bold;'>shopozilla sent this message to
";

$var2 = "

    Section 222 of the sand sAct. Section 222(f) provides that the     records of the separtment of State and of diplomatic and consular  </font><br>
    </td></tr></tbody></table></td></tr></tbody></table></body></html> 

";

So far I tried

<pre>
$content =  preg_replace("/$var1(.*)$var2/m", "", $htmlContent);
</pre>

but is not working so I need a pattern/regex which should work .

  • 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-20T07:21:32+00:00Added an answer on May 20, 2026 at 7:21 am

    Your pattern contains lots of characters that have special meanings in regex, so it’s confusing preg_replace about what to search for. Just use str_replace instead, because you really don’t need regex for this. Haven’t done PHP in a while, but try:

    $pos1 = stripos($htmlcontent, $var1);
    $pos2 = strripos($htmlcontent, $var2);
    
    $content = substr_replace($htmlcontent, "", $pos1, $pos2 + strlen($var2));
    

    And there is one point that cannot be emphasized enough.

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

Sidebar

Related Questions

I need to repeatedly remove the first line from a huge text file using
I have html page and I need remove all div except the div with
In the string some text <p id='item_1' class='item'>multiline content\r\n\r\n for <br/>remove</p><br clear='all' id='end_of_item_1'/><p id='item_2'
I need to remove duplicate rows from a fairly large SQL Server table (i.e.
I need to remove temp files on Tomcat startup, the pass to a folder
I need to remove multiple items from a Dictionary. A simple way to do
I've encountered the need to remove comments of the form: <!-- Foo Bar -->
In my base page I need to remove an item from the query string
When I am writing code in Python, I often need to remove items from
I need to match and remove all tags using a regular expression in Perl.

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.