Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Post New Thread Reply

Register GFY Rules Calendar
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 11-24-2009, 06:19 AM   #1
redwhiteandblue
Bollocks
 
redwhiteandblue's Avatar
 
Industry Role:
Join Date: Jun 2007
Location: Bollocks
Posts: 2,792
Regex to strip HTML comments

Trying to strip HTML comments from a web page, someone else must have done this.

I'm using
Code:
$page = preg_replace('/<!--(.|\s)*?-->/', '', $page
which works most of the time but sometimes causes an error. Is there a more reliable one?
redwhiteandblue is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 11-24-2009, 06:25 AM   #2
miXXXture
Confirmed User
 
miXXXture's Avatar
 
Industry Role:
Join Date: Jul 2009
Posts: 217
http://php.net/manual/en/function.strip-tags.php
miXXXture is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 11-24-2009, 06:40 AM   #3
redwhiteandblue
Bollocks
 
redwhiteandblue's Avatar
 
Industry Role:
Join Date: Jun 2007
Location: Bollocks
Posts: 2,792
Quote:
Originally Posted by miXXXture View Post
Nope, I don't want to strip all HTML tags - ONLY the HTML commented code (<!-- and --> and everything in between pairs of these).
redwhiteandblue is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 11-24-2009, 07:06 AM   #4
fris
Too lazy to set a custom title
 
fris's Avatar
 
Industry Role:
Join Date: Aug 2002
Posts: 55,262
try <!--(.*?)-->

instead
__________________
Since 1999: 69 Adult Industry awards for Best Hosting Company and professional excellence.


WP Stuff
fris is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 11-24-2009, 08:51 AM   #5
redwhiteandblue
Bollocks
 
redwhiteandblue's Avatar
 
Industry Role:
Join Date: Jun 2007
Location: Bollocks
Posts: 2,792
Quote:
Originally Posted by fris View Post
try <!--(.*?)-->

instead
Tht's probably what I started with but surely will just catch everything between the first opening comment tag and the last closing one?
redwhiteandblue is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 11-24-2009, 10:03 AM   #6
cyco_cc
Confirmed User
 
cyco_cc's Avatar
 
Join Date: Oct 2008
Posts: 344
Quote:
Originally Posted by redwhiteandblue View Post
Tht's probably what I started with but surely will just catch everything between the first opening comment tag and the last closing one?
No, the '?' part makes it non-greedy so it will match the first closing.

Edit: When is your regex breaking? The /<!--(.|\s)*?-->/ one?

Last edited by cyco_cc; 11-24-2009 at 10:05 AM..
cyco_cc is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 11-24-2009, 10:07 AM   #7
Tom_PM
Porn Meister
 
Industry Role:
Join Date: Feb 2005
Posts: 16,443
I was looking all through my old scripts for that to help you, but I think you've got it now.
__________________
43-922-863 Shut up and play your guitar.
Tom_PM is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 11-24-2009, 11:04 AM   #8
redwhiteandblue
Bollocks
 
redwhiteandblue's Avatar
 
Industry Role:
Join Date: Jun 2007
Location: Bollocks
Posts: 2,792
Quote:
Originally Posted by cyco_cc View Post
Edit: When is your regex breaking? The /<!--(.|\s)*?-->/ one?
Don't know, on most pages it happily strips out comments but on some it just returns null and I haven't figured out what the difference is with those pages yet.

EDIT just spotted this comment in the PHP user manual:

"As a pertinent note, there's an issue with this function where parsing any string longer than 94326 characters long will silently return null. So be careful where you use it at. "

Could be it.

Last edited by redwhiteandblue; 11-24-2009 at 11:08 AM..
redwhiteandblue is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.