Forum Moderators: open

Message Too Old, No Replies

PHP (includes, variable, print) How to in ASP?

Trying to learn ASP from a PHP perspective. :)

         

JAB Creations

12:51 am on Jan 11, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



First just the situation I'm in IoI...
Well I *finally* got to working on the technical aspects of my web development degree and I am in an ASP class (with ball track mice, ugg). However the techs are, well, I better not say (balltrack mice and no usb 2 drivers); so IIS isn't running so (and no one has a Wnidows based server) so we can't test ASP at all. I'll have to set it up on my home box (I'm running Apache for local testing purposes) but until I do I'll just have to figure this out on my own.

Ok now the code...I know a little bit of PHP. I learn by actually using code I learn as I have to get use to it. Well I have a lot of repetive code on my site and so naturally with PHP all I wanted to do was to put all that code in a single spot to call it from when needed.

1.) Includes - Calls a file where all my HTML code is located.

2.) Variables - Instead of putting the HTML over and over again I can just set it to a variable to be called from when I need it on the pages. My $vars are located in the includes.php/asp file.

3.) Print - Simply prints out the HTML code from the variable.

Here is my PHP code and from what the teacher subscribes to as AP (not sure he understands what I'm trying to do).

PHP

***index.php***
<?php
include("/public_html/themes/includes.php");

***(includes.php)***
$variable = '<span class="text">text</span>';

***index.php***
print $variable;
?>

ASP

***index.asp***
<%
<!--#include file = "/public_html/themes/includes.asp"-->
%>

***includes.asp***
<%
$variable='<span class="text">text</span>'
%>

***index.asp***
<%
response.write($variable)
%>

So right now I'm trying to figure out if this code is correct and should work in ASP as I know it would in PHP.

Looking forward to learning and knowing both ASP and PHP!

John

Easy_Coder

12:53 am on Jan 11, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



try

***index.asp***
<!--#include file = "public_html/themes/includes.asp"-->

***includes.asp***
<%
variable= "<span class=""text"">text</span>"
%>

***index.asp***
<%
response.write(variable)
%>

JAB Creations

1:30 am on Jan 11, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks EC!

Final code....

index.asp

<%
<!--#include file = "includes.asp"-->
response.write(testme)
%>

includes.asp

<%
testme="<span class=""test"">text</span>"
%>

It's different in that the includes can not be inside the ASP syntax (odd but ok). Double quotes are escaped by sending two double quotes.

What about single quotes?

Thanks again EC

John

Easy_Coder

4:47 am on Jan 11, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



single quote would be cool like this

<%
testme="<span class='test'>text</span>"
%>

mrMister

11:44 am on Jan 11, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



OK, I'm being a bit anally retentive here, but easy coder's code isn't doing precisely what you are doing in your code.

<%@ Page Language = "vbscript" %>
<%
Response.execute(/public_html/themes/includes.asp)
variable = "<span class=""text"">text</span>"
Response.write(variable)
%>

Note that you should really place the following line before using the variable...

Dim variable

This will produce more efficent code.

If you're used to PHP, I'd take a look at using PerlScript rather than VB in your ASP pages, you'll find it easier.

mrMister

11:59 am on Jan 11, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That line should be quoted (I made a mistake and can't edit it now)

Response.execute("/public_html/themes/includes.asp")

It's different in that the includes can not be inside the ASP syntax (odd but ok).

Easy_Coder used SSI, It's server dependent (nothing to do with ASP) and it can be used in PHP as well as with ASP on most web servers, but its functionality is slightly different.

Double quotes are escaped by sending two double quotes.

Yes, in VBScript you escape quotes by using two double quotes. If you are using another language in your ASP pages it will be different (you can escape quotes in the same was as PHP if you use PerlScript instead of VBScript)

What about single quotes?

There's no need to escape single quotes in VBScript.