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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:42:51+00:00 2026-05-31T01:42:51+00:00

I have this: $text = ‘text text text s html tagove <div id=content>ss adsda

  • 0

I have this:

$text = 'text text text s html tagove
<div id="content">ss adsda sdsa </div>
oshte text s html tagove';
$content = preg_replace('/(<div\sid=\"content\">)[^<]+(<\/div>)/i', '', $text);
var_dump($content); 

But if the <div id="content"></div> contains other tags, such as <b>,<i> etc, it does not work.

For example:

$text = 'text text text s html tagove
<div id="content"><b> stfu </b> ss adsda sdsa </div>
oshte text s html tagove';
  • 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-31T01:42:53+00:00Added an answer on May 31, 2026 at 1:42 am

    You can use lazy quantifiers instead.

    $s="foo<div>Some content is <b>bold</b>.</div>bar\n";
    
    print preg_replace("/<div>.+?<\/div>/i", "", $s);'
    

    output:

    foobar
    

    UPDATE per comments:

    [ghoti@pc ~]$ cat doit.php 
    <?php
    
    $text = 'text text text s html tagove
    <div id="content"><b> stfu </b> ss adsda sdsa </div>
    oshte text s html tagove';
    
    print preg_replace('/<div id="content">.+?<\/div>/im', '', $text) .  "\n";
    
    [ghoti@pc ~]$ php doit.php 
    text text text s html tagove
    
    oshte text s html tagove
    [ghoti@pc ~]$ 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this input text: <html><head><meta http-equiv=content-type content=text/html; charset=utf-8></head><body><table cellspacing=0 cellpadding=0 border=0 align=center width=603>
I have this html code <div id=mydiv> <div> <span>Text inside span</span> Text next to
I have this div: <div class=inauguration-image> I do not want this text to display,
I have this text-box on the page: <%= Html.TextBoxFor(m => m.STPData.ProjectName, new { @class
I have this text inside a div with a fixed width: Some headline (2009-10-10
I have this text file filled with some html code; <span>test</span><p>welcome</p> <span>Guest</span><p><img class=insertedImage src=/dynamictemplate/uploads/temp/167-5-IMG_0755.JPG
i have this jQuery code: $(#text_a).html('<textarea name = text>.$text_user.</textarea>'); And if I put in
I have this sample text, which is retrieved from the class name on an
I have this RTF text: {\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset0 Arial;}} {\colortbl ;\red0\green0\blue0;\red255\green0\blue0;} \viewkind4\uc1\pard\qc\cf1\fs16 test \b bold \cf2\b0\i
I have this kinda template text : Hello {#Name#}, Thanks for coming blah on

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.