Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

$value 1

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
0
0
Hi
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; ??
 
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 vic cherubini
malice365@hotmail.com
====
Knows: Perl, HTML, JavScript, C/C++, PHP, Flash, Director
====
 
I hate to disagree Vic, but,......
In this expression,
$value =~ s/<!--(.|\n)*-->//g;
the identified pattern is replaced with null.

-- regex explain --
s/<!--(.|\n)*-->//g;
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
 
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.
Sincerely,

Tom Anderson
CEO, Order amid Chaos, Inc.
 
Good enough. I always have to run these little critters to be sure, and I have not run this one.....

Thanks.




keep the rudder amid ship and beware the odd typo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top