Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here



I just want to know what those lines does ?

$value =~ s/<!--(.|\n)*-->//g;
$value =~ s/<([^>]|\n)*>//g;

They are in a guestbook.

One more thing.
How do I remove <a>,<*> etc.....  in a gusetbook
Only like $value =~ s/<*>//g; ??
Replies continue below

Recommended for you

RE: $value

The regular expression in the $value variable finds an HTML comment and replaces it with a \n (new line). It does this globally, hence the //g.

The second $value variable removes HTML tags, which is what you are trying to ask, I think..

I hope this helps,


vic cherubini
Knows: Perl, HTML, JavScript, C/C++, PHP, Flash, Director

RE: $value

I hate to disagree Vic, but,......
In this expression,
 $value =~ s/<!--(.|\n)*-->//g;
the identified pattern is replaced with null.

-- regex explain --
s - says replace
the three '/' are the pattern delimiters which contain /find pattern/replace pattern/
the find pattern <!--(.|\n)*--> appears to be an HTML comments
                         |      |       |
                         |      |     -->    end of HTML comment
                         |    (.|\n)*       dot says any char
                         |                     | says 'or' \n which is a new line
                         |                     * says zero or more occurrences of the .|\n pattern
                    open HTML comment

I don't have time to play with this, but, I don't think it will replace HTML comments with null unless the 's' switch is added to the 'g' to allow the regex engine to treat new lines as normal chars.  With out the 's', a multi-line comment will not match the find pattern..... I don't think... I does look like it would work for a single line comment.

'hope this helps  

 keep the rudder amid ship and beware the odd typo

RE: $value

gB, right on the correction to Vic about being removed rather than replaced with a newline.  However, I don't think you need the s switch since newlines are specifically being matched in the expression.

Tom Anderson
CEO, Order amid Chaos, Inc.

RE: $value

Good enough.  I always have to run these little critters to be sure, and I have not run this one.....


 keep the rudder amid ship and beware the odd typo

RE: $value

Thanks 4 all the answers

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close