By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,640 Members | 2,597 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,640 IT Pros & Developers. It's quick & easy.

Replace everything between two strings?

P: n/a
I need to replace everything between and including two snippets of HTML
code, for example:

</table></td></tr></table> klsdjff sd fsd fs fs df sdfs df sdf sd fsf d
<B><P> sfd sd fsdfs <br>

The </table></td></tr></table> and <br> parts will be the same. I want to
remove them and everything in between, including /n line breaks.

Can't figure out the regex in PHP to do this.... any ideas?


Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
do********@nowhere.com idiotically stated:
I need to replace everything between and including two snippets of
HTML code, for example:

</table></td></tr></table> klsdjff sd fsd fs fs df sdfs df sdf sd fsf
d <B><P> sfd sd fsdfs <br>

The </table></td></tr></table> and <br> parts will be the same. I
want to remove them and everything in between, including /n line
breaks.

Can't figure out the regex in PHP to do this.... any ideas?


use stristr().

First split up the whole string based on your first delimiter
(</table></td>....). take the end part of that result (which is now
everything after your first delim). Then split it up again, but use your
2nd delimiter (<br>). Use the beginning part of that result. you now have
a string that is between your two delimiters.

now use that string and stristr again on the original, full string, and
simply replace it with a empy space.

--
brian ... brian@cc
www.brianculler.com
Jul 17 '05 #2

P: n/a
Uzytkownik "DesignGuy" <do********@nowhere.com> napisal w wiadomosci
news:o0n8c.83725$1p.1228208@attbi_s54...
I need to replace everything between and including two snippets of HTML
code, for example:

</table></td></tr></table> klsdjff sd fsd fs fs df sdfs df sdf sd fsf d
<B><P> sfd sd fsdfs <br>

The </table></td></tr></table> and <br> parts will be the same. I want to
remove them and everything in between, including /n line breaks.

Can't figure out the regex in PHP to do this.... any ideas?


$text = preg_replace('!</table></td></tr></table>.*?<br>!s', '', $text);

The key here is the s modifier, which tells PCRE that you want the dot to
match \n as well.
Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.