I am trying to move a old Classic ASP site to run in PHP. I am rewriting bits of it, however I have come across the following function that is causing me some problems. Basically the function FixForSQL is run on everything before adding it to the database and then FixForHTML is run on data returned with a SQL query to format it for display.
At the moment if I display a block of text retrieved from the database in PHP it shows as one huge block of text with no paragraph breaks, I presume because I haven’t done the replace of Chr(13) and whatever Chr(9) is!
Does anyone know how to reproduce whatever is happening in PHP 5?
Function FixForHTML(tmpText1)
Dim tmpText2
tmpText2 = tmpText1
tmpText2 = Replace(tmpText2,Chr(13),"</p><p>" & vbCrLf)
tmpText2 = Replace(tmpText2,Chr(9),"    ")
FixForHTML = tmpText2
End Function
Function FixForSQL(tmpText1)
Dim tmpText2
tmpText2 = tmpText1
tmpText2 = Replace(tmpText1,vbCrLf,Chr(13))
tmpText2 = Replace(tmpText2,Chr(39),String(2,39))
FixForSQL = tmpText2
End Function
Chr(13)is the the character whose ASCII code is 13. You can get it in PHP with, you guessed,chr(13).13is the code for Cariage return. While9is for Horizontal tab. In PHP you can also get those characters in a parsable string (one delimited by"s) with\n, respectively\t.ASCII table
Sample code for PHP:
As for the
FixForSQLfunction, it just replaces'characters with''to escape them for the SQL query.