ASP to PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
smoogle
Forum Newbie
Posts: 7
Joined: Thu Jul 20, 2006 6:16 am

ASP to PHP

Post by smoogle »

patrikG | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I am currently trying to make the jump from ASP to PHP coding and am aiming to convert my personal website to php to try to get my head around the basics. On my current site I use ASP sub proceedures to define modular content then I just call the sub proceedure in the page where I want it to display. This has been my approach for many sites I have coded as it seperates the content from the design and is much easier to manage the code. I now need to port this over to PHP or if there is a better way to do it I would very appreciative. Here is an example:

Code: Select all

<html>

<% sub MyModule() %>
Here is the content
<% end sub %>

<head>
</head>

<body>

<% Call MyModule() %>

</body>
</html>
patrikG | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Last edited by smoogle on Thu Jul 20, 2006 7:16 am, edited 1 time in total.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Here are 2 examples...

Code: Select all

<?php
include 'modules/myContent.php';
?>

Code: Select all

<html>
<?php
function MyModule() {
  ?>
Here is the content
  <?php
}
?>
<head>
</head>

<body>

<?php MyModule(); ?>

</body>
</html>
We could give you better examples if you posted the actual code though..

Might want to grab a copy of the manual as well.
smoogle
Forum Newbie
Posts: 7
Joined: Thu Jul 20, 2006 6:16 am

Post by smoogle »

Thank you very much for the help, this worked a treat...sorry about not posting correctly. Thanks for the advice... will check out the manual.

When using the following php include reference..

Code: Select all

<?php
include 'modules/myContent.php';
?>
how can I make the include reference a file using an absolute reference?

In asp I can do the following..

Code: Select all

<!--#include virtual = "/modules/myContent.asp"-->
if I use the "/" to reference the site root, in php it doesn't work.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

You can use either the full path or a relative path. The path will not be relative to where the PHP file is actually located though. It will be relative to where the file is being called from.

So let's say you have something like this...

index.php
/includes/header.php
/includes/footer.php
/includes/functions.php

In index.php, you want to include the header, so you can use

Code: Select all

include 'includes/header.php';
Now, lets say you want header.php to include the functions file. In header.php you would need to put the same thing as above..

Code: Select all

include 'includes/functions.php';
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

Post by daedalus__ »

Welcome to PHP you are going to love it!
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

You are going to dig PHP so much more than ASP. Moreso when you get used to line terminators ( ; ) and variable identifiers ( $ ). Oh yeah, and that whole Subroutine vs Function stuff. But PHP rocks... you'll love it.

The smilies ate part of my post again...
Post Reply