R – Can you declare a variable in ASP classic like this

asp-classicheredocvariables

I am trying to see if this can be done in classic ASP:

Dim myVar
myVar = <<< END
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
    <title>test</title>
</head>

<BODY>
END

I can do this in PHP, but I am not positivte if it can be done in ASP.
Problem is I need to handle the HTML output via a variable, and I don't want to go through the HTML and convert " to ""

EDIT:

I've found that this is called HEREDOC syntax in PHP.

Since its been asked, what I am trying to do is store HTML type tags (which may contain ', " characters which would otherwise break
myVar = "<stuff color="red">here</stuff>"

so I would need to fix it by replacing color="red" with color=""red""

PART OF THE PROBLEM:

I don't want to have to replace " with "" for the content as I assign it, I guess a HEREDOC syntax is not available for ASP classic.

OK FINE… 😛

Since everyone is asking me WHY I am going about it this way, here is why, I have to support this old ASP code, I don't want to, but suddenly the scope of this old app changes that they want the contents (which used to be an HTML page) to be emailed, SO… I wanted to HEREDOC the HTML output, pass it to the mail function and have it email. Having said that, I know its sloppy, and I know it works better the other way, however this is what the job called for, I didn't want to re-write it, I just wanted to augment the output from HTML to HTML-EMAIL…

Hope that makes more sense 😉

Best Answer

No. One language's syntax isn't going to work in a different language. You can, however, assign a string literal to the variable:


Dim myVar
myVar = _
    "<html xmlns=""http://www.w3.org/1999/xhtml"" lang=""en"" xml:lang=""en"">" & vbCrLf & _
    "<head>" & vbCrLf & _
    "    <title>test</title>" & vbCrLf & _
    "</head>" & vbCrLf & _
    "" & vbCrLf & _
    "<BODY>" & vbCrLf

Related Topic