Page 1 of 1

ASP to PHP

Posted: Thu Jul 20, 2006 6:24 am
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]

Posted: Thu Jul 20, 2006 6:32 am
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.

Posted: Thu Jul 20, 2006 7:14 am
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.

Posted: Thu Jul 20, 2006 7:27 am
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';

Posted: Thu Jul 20, 2006 11:22 am
by daedalus__
Welcome to PHP you are going to love it!

Posted: Thu Jul 20, 2006 11:26 am
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...