--- 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
_____
James D. Keeline
http://www.Keeline.com http://www.Keeline.com/articles
http://Stratemeyer.org http://www.Keeline.com/TSCollection
http://www.ITeachPHP.com -- Free Computer Classes: Linux, PHP, etc.
Summer Semester Begins Jun 20 -- New Classes Start Every Few Weeks.
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/