LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   [PHP] Put code in a seperate file (https://www.linuxquestions.org/questions/programming-9/%5Bphp%5D-put-code-in-a-seperate-file-590571/)

Ephracis 10-09-2007 12:44 PM

[PHP] Put code in a seperate file
 
I have a page with a div-tag.
[html]
<html>
<head>
<title>My Page</title>
</head>

<body>
The cow says:
<div id="mydiv"></div>
</body>
</html>
[/html]

I want to put some Javascript or PHP code inside there to put the content of the following file into the div called "mydiv":
PHP Code:

<b>
<?
echo "Moo";
?>
</b>


lucazorzi 10-09-2007 12:55 PM

Can't you use
PHP Code:

include('path/to/file.php'); 

?

Ephracis 10-09-2007 12:58 PM

Quote:

Originally Posted by lucazorzi (Post 2918614)
Can't you use
PHP Code:

include('path/to/file.php'); 

?

How will that put the content of path/to/file.php inside that div?

Wim Sturkenboom 10-09-2007 01:19 PM

Code:

<html>
<head>
<title>My Page</title>
</head>

<body>
The cow says:
<div id="mydiv"><?php include('somefile.php'); ?></div>
</body>
</html>

Something like that? Not checked for correct syntax and it's a while ago that I touched php from scratch.

Ephracis 10-09-2007 01:40 PM

Quote:

Originally Posted by Wim Sturkenboom (Post 2918644)
Code:

<html>
<head>
<title>My Page</title>
</head>

<body>
The cow says:
<div id="mydiv"><?php include('somefile.php'); ?></div>
</body>
</html>

Something like that? Not checked for correct syntax and it's a while ago that I touched php from scratch.

Cool, I have only been using include in the header before. Anyway it worked perfectly. I was able to put only HTML-code inside the php-file and use PHP to include it. :)

But I wish there was a way to use Javascript to change the content to be read from another file containing HTML/PHP.

nc3b 10-09-2007 02:57 PM

Quote:

But I wish there was a way to use Javascript to change the content to be read from another file containing HTML/PHP.
If you haven't done that already, take a look at "AJAX" . It may suit your needs. Cheers :)

Ephracis 10-09-2007 04:10 PM

Quote:

Originally Posted by nc3b (Post 2918761)
If you haven't done that already, take a look at "AJAX" . It may suit your needs. Cheers :)

I have done that but it is too complex. All tutorials and other stuff I find on the net contains of frameworks and a vast number of documents I need to read. I just do not know where to start. :/

nc3b 10-10-2007 01:06 PM

Start here then. The first thing you see will help you understand why I double-quoted "AJAX". Cheers :)


All times are GMT -5. The time now is 10:46 PM.