Sign in to follow this  
Followers 0
n9mfk9

_FileWriteFromArray?

3 posts in this topic

#1 ·  Posted (edited)

Hi everyone

here my code

#include <array.au3>
#include<File.au3>

$tagname ="" 
$ext =".txt"
$sInput = ""

;$tagname = ""

$FileIn = @ScriptDir & "\tagslist"&$ext
$Fileout =  @ScriptDir & "\mytest"&$ext
;$hFileOut = FileOpen($FileOut, 2)
$sInput = FileRead($FileIn, FileGetSize($FileIn))
        If @error = 1 Then
        MsgBox(0, "Error", "Unable to open file."&$FileIn)
    Exit
EndIf

;MsgBox(0,"test", $FileIn)
$avInput = StringSplit($sInput, @CRLF, 1)
;_ArrayDisplay($avInput, "$avInput")

Global $avOutput[$avInput[0] + 1] = [$avInput[0]]
For $n = 1 To $avInput[0]
    $sFormatted = ""
    $tag = StringRegExp($avInput[$n], "%.*?%", 1)
    If @error = 0 Then
      ;$tagname =  $tag[0]
        Global $tagname[Ubound($tag)]

           $tagname[0] = $tag[0]
            $tagname[0] = StringReplace($tagname[0],'-','_')
            $tagname[0] = StringReplace($tagname[0],'<','LT')
            $tagname[0] = StringReplace($tagname[0],'>','GT')
            $tagname[0] = StringReplace($tagname[0],'=','')
            $tagname[0] = StringReplace($tagname[0],'/','_')
            $tagname[0] = StringReplace($tagname[0],',','CM')
        
        
;MsgBox(0,"",$tagname)
     ; ConsoleWrite("Debug: " & $n & ":  " & $tag[0] & @LF)
        $sFormatted = "$" & StringReplace($tagname[0], "%", "") & ' = "' & $tag[0] & '" '
      ;MsgBox(0,"",$sFormatted)
;ConsoleWrite("Debug: $sFormatted = " & $sFormatted & @LF)
    EndIf
    $avOutput[$n] = $sFormatted & "\\ " & StringRegExpReplace($avInput[$n], "\.{2,}", "", 0)
 ; ConsoleWrite("Debug: Output " & $n & ":  " & $avOutput[$n] & @LF)
Next

Dim $avohdr
$avohdr=  _ArrayCreate("<?php" & @CRLF & "// converted"& $FileIn& "to"& $FileOut & "for php tags" & @CRLF & _
"// by " & "// Author: n9mfk" & @CRLF & "//// ---------------------------------" & @CRLF & _
"// allow viewing of generated source"&@CRLF&@CRLF&"if ( \$_REQUEST['sce'] == 'view' ) {" & @CRLF & _
" download('view');"& @CRLF & "exit;}"&@CRLF)
_ArrayDisplay($avohdr, "$avOutput")

$hFileOut = FileOpen($FileOut, 2)
    _FileWriteFromArray($hFileOut, $avohdr,0)
    _FileWriteFromArray($hFileOut, $avOutput,1)  



        FileClose($hFileOut)
;MsgBox(0,"test", $avOutput)
;_ArrayDisplay($avOutput, "$avOutput")

here the code i need help with

Dim $avohdr
$avohdr=  _ArrayCreate("<?php" & @CRLF & "// converted"& $FileIn& "to"& $FileOut & "for php tags" & @CRLF & _
"// by " & "// Author: n9mfk" & @CRLF & "//// ---------------------------------" & @CRLF & _
"// allow viewing of generated source"&@CRLF&@CRLF&"if ( \$_REQUEST['sce'] == 'view' ) {" & @CRLF & _
" download('view');"& @CRLF & "exit;}"&@CRLF)
_ArrayDisplay($avohdr, "$avOutput")

$hFileOut = FileOpen($FileOut, 2)
    _FileWriteFromArray($hFileOut, $avohdr,0)

when i look at my file

the <?php is printed on lne 2 line 1 ins blank how can i move it to line 1

thanks Beau

Edited by n9mfk9

Share this post


Link to post
Share on other sites



here the code i need help with

Dim $avohdr
$avohdr=  _ArrayCreate("<?php" & @CRLF & "// converted"& $FileIn& "to"& $FileOut & "for php tags" & @CRLF & _
"// by " & "// Author: n9mfk" & @CRLF & "//// ---------------------------------" & @CRLF & _
"// allow viewing of generated source"&@CRLF&@CRLF&"if ( \$_REQUEST['sce'] == 'view' ) {" & @CRLF & _
" download('view');"& @CRLF & "exit;}"&@CRLF)
_ArrayDisplay($avohdr, "$avOutput")

$hFileOut = FileOpen($FileOut, 2)
    _FileWriteFromArray($hFileOut, $avohdr,0)

when i look at my file

the <?php is printed on lne 2 line 1 ins blank how can i move it to line 1

thanks Beau

This is actually a problem with the _FileWriteFromArray() function. The relevant part of the function is this:

; Write array data to file
    Local $ErrorSav = 0
    For $x = $i_Base To $i_UBound
        If FileWrite($hFile,  @CRLF & $a_Array[$x]) = 0 Then
            $ErrorSav = 3
            ExitLoop
        EndIf
    NextoÝ÷ Ùhbr§±êí²Ø^ì%wªÁSæé^éí¡ûayªëk+âqàLDX¢çÜjKajÖòë-yØ­x2¢êßW»u©Ýr§)ඨébëhjëh×6     If FileWrite($hFile,  $a_Array[$x] & @CRLF) = 0 Then

I think that make more sense, too.

:D


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


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
Sign in to follow this  
Followers 0