PHP to replace URL

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
wayneob
Forum Newbie
Posts: 8
Joined: Thu Mar 26, 2009 8:57 am

PHP to replace URL

Post by wayneob »

Hi guys,

This is probably easy for some of you, but cant figure it out myself and no luck on Googling.

Ok I have 3 websites on different domains & all sites are the same.. If I update an include file (say a menu/navigation) and the include has direct links to subfolders/page say: http://www.mysite.com/myfolder/mypage/index.php, I dont want to have to update all the links on each include, on all sites, I just want to update 1 include (master) and upload it to all sites, If you follow?

Maybe there is a simple javascript code to replace the URL example:

Code: Select all

<a href="javascriptcode;myfolder/mypage/index.php">My page</a>
but I'm hoping for similar method in PHP.

I tried to do a config.php include using

Code: Select all

<?php include_once "includes/config.php"?>
config.php

Code: Select all

<?php
$SITE_URL = 'http://www.ssdltd.com.au';
?>
and replacing the url with this;

Code: Select all

<a href="<? php $SITE_URL; ?>myfolder/mypage/index.php">My page</a>
didnt work obviously, so is there an easier process for this that I can use?

Note: I'm not a PHP novice and the pages are html layout with php includes so pages are saved as php and are not just php language.

Would appreciate any help with this!
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: PHP to replace URL

Post by jackpf »

You're not echoing the url.
wayneob
Forum Newbie
Posts: 8
Joined: Thu Mar 26, 2009 8:57 am

Re: PHP to replace URL

Post by wayneob »

and this will fix my code?
...how to please! :)
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: PHP to replace URL

Post by jackpf »

Code: Select all

<?php echo $SITE_URL;?>
jmaker
Forum Newbie
Posts: 16
Joined: Tue May 21, 2002 11:13 pm

Re: PHP to replace URL

Post by jmaker »

Maybe he was going for this?

Code: Select all

 
<?=$SITE_URL?>
 
wayneob
Forum Newbie
Posts: 8
Joined: Thu Mar 26, 2009 8:57 am

Re: PHP to replace URL

Post by wayneob »

Thanks! :)

works without the config!

Code: Select all

<?php echo $SITE_URL;?>

Solved!
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: PHP to replace URL

Post by jackpf »

jmaker wrote:Maybe he was going for this?

Code: Select all

 
<?=$SITE_URL?>
 
Maybe. But that's not guaranteed to work, since short tags have to be enabled. I think we shall just keep this simple :P
Post Reply