Jump to content

search for text in html file


Recommended Posts

$file = FileOpen("test.html", 0)

; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf


While 1
    $text = FileRead($file, 100000)
    If @error = -1 Then ExitLoop
Wend

FileClose($file)












$text = StringReplace("file:///E:/root/Apache/htdocs", "", "")
$numreplacements = @error
MsgBox(0, "New string is", $text)
MsgBox(0, "The number of replacements done was", $numreplacements)


$file = FileOpen("test.html", 1)

; Check if file opened for writing OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

FileWrite($file, $text)


FileClose($file)


MsgBox(0, "search", "done")

i need to search a html file for text string "file:///E:/root/Apache/htdocs" and then delete it from the file as somone made a big mistake as you see. there is about 7000 wrong entries.... but i cant get my script to work, i foth this was easy. meybe somone can help me here....

Edited by HARNOvHARNO
Link to post
Share on other sites

Three mistakes are here:

1. Strange loop at begin, not sure why it not works, but this loop not need anyway

2. StringReplace not take your text string

3. Second time file opens in append mode, not overwrite

Also, if you use latest beta num replacements now in the @extended macro.

Here is fixed code:

$file = FileOpen("test.html", 0)

; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

$text = FileRead($file, FileGetSize("test.html"))

FileClose($file)

$text = StringReplace($text, "file:///E:/root/Apache/htdocs", "")
$numreplacements = @extended; @error
MsgBox(0, "New string is", $text)
MsgBox(0, "The number of replacements done was", $numreplacements)


$file = FileOpen("test.html", 2)

; Check if file opened for writing OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

FileWrite($file, $text)


FileClose($file)


MsgBox(0, "search", "done")
Edited by Lazycat
Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...