Results 1 to 7 of 7

Thread: PHP : eregi_replace problem

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2000
    Location
    Chennai , India
    Posts
    44
    I have a html page like this
    Code:
    <script language="vbscript">
    some script
    </script>
    
    Some text
    
    <script language="vbscript">
    some more script
    </script>
    
    Some more text
    I want to remove the scripts so i used the following code:

    Code:
    $open = fopen("file.html", "r");
    $read = fread($open,  20000);
    fclose($open);
    
    $read = eregi_replace("<script>(.*)</script>", "" , $read);
    what it outputs is just Some more text. The scripts are gone but along with them the Some text. I dont want some text to be erased.

    Please Help,
    Thanks in advance,
    Rabin
    Rabin
    Windows : Visual Basic 6 Enterprise / 3.0 (16-bit)
    DOS : QBasic 4.5 , Visual Basic For DOS
    Web : HTML , VBScript , PHP (Learning)

  2. #2
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    this is a guess

    Code:
    $open = fopen("file.html", "r");
    $read = fread($open,  20000);
    fclose($open);
    
    $read = eregi_replace("<script>", "" , $read);
    $read = eregi_replace("</script>", "" , $read);
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  3. #3
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    never mind that wont work.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  4. #4

    Thread Starter
    Member
    Join Date
    Aug 2000
    Location
    Chennai , India
    Posts
    44
    never mind that wont work.
    Yeah, that'll just remove the <script> and </script> tags but the code will be displayed.
    Rabin
    Windows : Visual Basic 6 Enterprise / 3.0 (16-bit)
    DOS : QBasic 4.5 , Visual Basic For DOS
    Web : HTML , VBScript , PHP (Learning)

  5. #5
    New Member
    Join Date
    Jan 2001
    Posts
    6

    must use explode

    Hi,

    use explode() to chop up the string into an array, then loop through the array doing

    $read[$i] = eregi_replace("<script>(.*)</script>", "" , $read[$i]);

    on each element, then implode() all the parts back into a string

    Hope that's not to confusing--i don't have enough time to provide sample code

    Best Regards,
    Bill Zeller

  6. #6

    Thread Starter
    Member
    Join Date
    Aug 2000
    Location
    Chennai , India
    Posts
    44
    What should I use as a seperator for explode() ? </script> ?
    Rabin
    Windows : Visual Basic 6 Enterprise / 3.0 (16-bit)
    DOS : QBasic 4.5 , Visual Basic For DOS
    Web : HTML , VBScript , PHP (Learning)

  7. #7
    New Member
    Join Date
    Jan 2001
    Posts
    6
    yup, use </script>. Then do something like

    eregi_replace("<script>(.*)", "", $var[$i])

    If that doesn't clarify it I might just have to write up some working code

    Best Regards,
    Bill Zeller

Posting Permissions

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



Click Here to Expand Forum to Full Width