This example will show you how use a string in VB to create PHP code.In order to do this, you need a string to store your PHP page and a function that I will list at the bottom of the page for you to put in a module. This code is written in VB.NET
Public Sub CreatePage(ByVal HTMLTitle As String, ByVal HTMLText As String, ByVal HTMLFileName As String)
Code:
Dim strFile As String
' ----------------------
' -- Prepare String --
' ----------------------
strFile = ""
' --------------------
' -- Write Starter --
' --------------------
strFile = "<html>" & vbNewLine
strFile = strFile & "<head>" & vbNewLine
strFile = strFile & "<title>" & HTMLTitle & "</title>" & vbNewLine
strFile = strFile & "</head><body>" & vbNewLine
strFile = strFile & HTMLText & vbNewLine
strFile = strFile & "</body></html>"
SaveTextToFile(strFile, "C:\" & HTMLFileName & ".html")
End Sub
Now we're done with the sub for creating the page, this is the only other snippet of code you will need, this needs to go into a
module of your program.
Public Function SaveTextToFile(ByVal strData As String, _ ByVal FullPath As String, _ Optional ByVal ErrInfo As String = "") As Boolean
Code:
Dim Contents As String
Dim Saved As Boolean = False
Dim objReader As IO.StreamWriter
Try
objReader = New IO.StreamWriter(FullPath)
objReader.Write(strData)
objReader.Close()
Saved = True
Catch Ex As Exception
ErrInfo = Ex.Message
End Try
Return Saved
End Function
As you can see, the code has a wide range of uses, such as taking old INI databases from your applications and being able to turn them into a useable webpage. Just take the strFile and add onto it with any HTML code or even PHP, all you'd have to do is change the ending on the save function inside the CreatePage sub.
Bookmarks