Hi James,
$contents = preg_replace("/<\?.+?\?>/s", "", $contents);
It works and removes all the php.I'd be thinking of using strip_tags(); to use temporarily. Just bought "Mastering Regular Expressions", but haven't mastered much yet, *grin*. I'll read up on "?" and what it does. Thanks for the fix. ----- Original Message ----- From: "James Keeline" <[EMAIL PROTECTED]> To: <[email protected]> Sent: Thursday, July 21, 2005 2:52 PM Subject: Re: [php-list] regex problem > --- Bob <[EMAIL PROTECTED]> wrote: > >> Hi James, >> Yes, I'm displaying just the contents. >> The php doesn't display, but it's there if anyone looks at the source. >> >> Tried it with an "s":- >> $contents = preg_replace("/<\?.+\?>/s", "", $contents); >> but it also removes all the html. >> >> There's an include header at the beginning, >> some html tags with the content and the odd php, >> then an include footer at the end. >> >> It must see the first "<?php" then remove everything including the html, >> right through to the last closing "?>" > > > This is another default behavior of regular expressions. They are "greedy" by > default and will make the largest match possible in the range of characters > examined. If you want the shortest match possible you can add a question mark > after the .* like this: > > $contents = preg_replace("/<\?.+?\?>/s", "", $contents); > ^ > > This may only remove the first set of PHP tags, by the way. > > > You might also want to consider the strip_tags() function and allow certain > HTML you want to see and remove everything else which looks like an HTML tag. > See the docs (http://www.php.net/strip_tags) for details. > > James Community email addresses: Post message: [email protected] Subscribe: [EMAIL PROTECTED] Unsubscribe: [EMAIL PROTECTED] List owner: [EMAIL PROTECTED] Shortcut URL to this page: http://groups.yahoo.com/group/php-list Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/php-list/ <*> To unsubscribe from this group, send an email to: [EMAIL PROTECTED] <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/
