Re: Regular Expressions - Between HTML Tags

From: Date: Mon, 27 Nov 2000 04:13:19 +0000
Subject: Re: Regular Expressions - Between HTML Tags
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-27304@lists.php.net to get a copy of this message
Jeremy: > I am trying to change some HTML files into text files for entry into a database. I would like > to know how to remove anything between a certain tag(Ex Title). > > $tabtotrim = > eregi_replace('^.+<TITLE>.+</TITLE>$','',$tabtotrim); Several problems here. First, I imagine your file will have stuff before and after the <title> tags, so ditch the "^" and "$". Second, you don't want to replace text that's not the tags or between the tags, so drop the ".+" at the beginning. Third, use ".*" rather than ".+" between the <title> tags because, for some reason, it may have nothing there. So, the final expression would be: $tabtotrim = eregi_replace('<TITLE>.*</TITLE>','',$tabtotrim); Oh, by the way, turn line wrapping on for outgoing email messages so they'll quote properly when people reply. Enjoy, --Dan -- PHP scripts that make your job easier http://www.analysisandsolutions.com/code/ SQL Solution | Layout Solution | Form Solution T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y 4015 7 Ave, Brooklyn NY 11232 v: 718-854-0335 f: 718-854-0409

« previous php.general (#27304) next »