Altering the code in a PHP include

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
SteveMellor
Forum Commoner
Posts: 25
Joined: Mon Jun 26, 2006 7:43 am

Altering the code in a PHP include

Post by SteveMellor »

I am having problems... that's wrong. I have an issue I should say, with php and includes that I need to find a solution for and wondered if there was anyone on here that might know of a solution.

Firstly, the back story

I am setting up web pages like this at the moment:

Code: Select all

<?php include("header.php");?>

<div class="about_title">Article Title</div>

<div class="abour_cont">
Article Content
</div>

<?php include("footer.php");?>
The header and the footer php files include layout information and standard bits for the site, including SEO bits, keywords and the navigation. I wanted to have SEO friendly URLs for some of the pages (the dynamic ones) and so studiously set about writing the .htaccess file only to find out that the host who I have to use not only doesn't allow the use of rewriting on there site.

A quick test later and I discovered that I can do this another way but it throws up a problem. Currently all the images that I have, including the CSS file, are relitave links. I am loathed to have to rewrite them all and so wondered if there was another way of doing it.

And so to the problem:

How can I take a php file and change all of the links within it and then include it on the page that I am creating. I was thinking about using str_replace but that didn't seam to work.

If anybody has any thoughts then I would be more than grateful and I am sure this could be of use to others who may have the same (or similar) issues.

All the best

Steve
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Seriously, I would just rewrite them. To do so on the fly for every page load will really be making your server do a lot of work it shouldn't have to do.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

How about using the <base> tag?
SteveMellor
Forum Commoner
Posts: 25
Joined: Mon Jun 26, 2006 7:43 am

Post by SteveMellor »

Everah wrote: Seriously, I would just rewrite them. To do so on the fly for every page load will really be making your server do a lot of work it shouldn't have to do.
I know, sometimes though I just need to so;ve these problems :wink:
feyd wrote: How about using the <base> tag?
Thank you, of course. It works perfectly. :D
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

All your <base/> are now belong to feyd!
SteveMellor
Forum Commoner
Posts: 25
Joined: Mon Jun 26, 2006 7:43 am

Post by SteveMellor »

oh dear
Post Reply