SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 1999
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not very good at these expressions.

    with the following code

    my $BlockTag;
    $HTML_Text =qq~all
    about
    <SCRIPT what>
    the script
    </SCRIPT>
    html
    ~;
    my $BlockTag;
    foreach $BlockTag ('SCRIPT', 'STYLE') {
    my $NewText = '';
    foreach (split(m!</$BlockTag>!i, $HTML_Text)) {
    if (m!^(.*?)<$BlockTag!i) {
    $NewText .= $1;
    }
    else {
    $NewText .= $_;
    }
    }
    $HTML_Text = $NewText;
    }
    print $HTML_Text


    i wish to remove the lines between the <SCRIP.. till </SCRIPT> and be left with

    all
    about
    html

    but the code only works if the first word is <SCRIPT, if not it just put out silly stuff.

    any ideas?
    thanks

  2. #2
    Destiny Manager Plebius's Avatar
    Join Date
    Nov 1999
    Posts
    682
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    something like this might work. havent tested it though.


    foreach $strip ('script', 'style')
    {
    if ($HTML =~ /<$strip/)
    {
    $HTML =~ s/<$strip([^$strip]*)$strip>//ig;
    }
    }

  3. #3
    SitePoint Enthusiast
    Join Date
    Aug 1999
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you LuZer, your code is simpler and it works with the following changes:

    here is the code that would work

    foreach $strip ('script', 'style'){
    if ($HTML_Text =~m/<$strip/i){
    $HTML_Text =~s/<$strip.*$strip>\n//sig;
    }
    }
    note the /s at the end.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •