Click to See Complete Forum and Search --> : Text block search and replace using html comment tags as markers...


molly
07-01-2004, 01:48 PM
I'm trying to write a script that will search through a html file, looking at consecutive blocks of text, using html comments as start and end tags for each block. I want the script to search for a specific string, specified by the user user via a form, in each block of text. Once theat string is found I want to delete the block of text, including the markers containing that string.
So far, i have the script accepting the string form the user, but i'm not quite sure how to go about searching and replacing within a html file under such conditions.

Any suggestions would be greatly appreciated!!
Thanks!

molly.

simpson97
07-01-2004, 04:17 PM
This may give you some ideas:
#!/usr/bin/perl

$FORM{'passed_var'} = "commented text";
$html_str = "ssssssshjkvf;f;f\n<!-- commented text -->nnnn hhjh wwwww";
print "Before: $html_str\n";
$html_str =~ s/\n//g;
$html_str =~ s/<!-- $FORM{'passed_var'} -->//g;
print "After: $html_str\n";
exit;