User login

Delete text between and including identifying strings

Internet answered this question for Agaric, and we'll make it easier for the next person to find the answer!

remove HTML within markers
regexp strip all between two snippets
regexp delete between two keywords
php delete between strings

There's a great, informative post – just in response to a question on a forum – on how to do it with a regular expression here:

http://www.programmingtalk.com/showthread.php?threadid=39966

With this answer:

$string = preg_replace( '/\<body\>.*\<table/Usi', '<body><table', $string ); 

Our modification (main difference, not re-adding the search strings) worked quite nicely to remove unwanted text hardcoded into another Drupal module, the otherwise wonderful Video module in 4.7:

    // dirty, dirty hack to get around video 4.7 not allowing any way to
    // remove the 'Problems viewing' text without redoing the whole output
        $vid = preg_replace( '/\<p\>\nProblems viewing.*\n\<\/p\>/Usi', '', $vid );

Internet answered this question for Agaric, and we'll make it easier for the next person to find the answer!

remove HTML within markers
regexp strip all between two snippets
regexp delete between two keywords
php delete between strings

There's a great, informative post – just in response to a question on a forum – on how to do it with a regular expression here:

http://www.programmingtalk.com/showthread.php?threadid=39966

With this answer:

$string = preg_replace( '/\<body\>.*\<table/Usi', '<body><table', $string ); 

Our modification (main difference, not re-adding the search strings) worked quite nicely to remove unwanted text hardcoded into another Drupal module, the otherwise wonderful Video module in 4.7:

    // dirty, dirty hack to get around video 4.7 not allowing any way to
    // remove the 'Problems viewing' text without redoing the whole output
        $vid = preg_replace( '/\<p\>\nProblems viewing.*\n\<\/p\>/Usi', '', $vid );

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.