/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Include section of php file

Hi

I want to be able to include a section of a php file, rather than the whole thing. I figured just use a function and call the external script in the head:

[code=php]

function writeMyName()
{
echo “Kai Jim Refsnes”;
}

[/code]

[code=html]

<script type=”text/php” src=”external.php”></script> // in the head

<?php writeMyName(); ?> // in the body

[/code]

Doesn’t seem to work. Saw some people using “text/javascript” for a php file, tried it, doesn’t work.

Any help?!

?

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@StevishMar 16.2009 — Is <?php include('external.php'); ?> what you're looking for? if all you have in external.php is functions, then you could include the code anywhere.
Copy linkTweet thisAlerts:
@lardauthorMar 16.2009 — Thanks Stevish, but no! I've got one file that is going to dynamically create lots pages - specifically reviews. I need to insert sections of dynamic content in various places, rather than in one lump.

If I use "include" I have to have seperate files for each page and for each section - which is a lot of files, and not too convenient for editing.
Copy linkTweet thisAlerts:
@ryanlundMar 16.2009 — Ok i cant for the life of me work out what your second post was talking about but i think what stevish meant was something along the lines of

<i>
</i>&lt;?php

include("external.php");

writeMyName();
?&gt;


because you cant include a php file the same way as a javascript file. other than that i have no idea what you mean with the rest of it

Ryan
Copy linkTweet thisAlerts:
@lardauthorMar 16.2009 — I think I've realised what I need to do - just use include but only have functions in the target file.
Copy linkTweet thisAlerts:
@lardauthorMar 16.2009 — Haha! Thanks ryan - posted at the same time as me ?
Copy linkTweet thisAlerts:
@ryanlundMar 16.2009 — Haha, no worries mate.

Think my bed is calling me any second though
×

Success!

Help @lard spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.14,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...