Page 1 of 1

PHP to replace URL

Posted: Sat Sep 26, 2009 5:40 am
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!

Re: PHP to replace URL

Posted: Sat Sep 26, 2009 6:07 am
by jackpf
You're not echoing the url.

Re: PHP to replace URL

Posted: Sat Sep 26, 2009 6:11 am
by wayneob
and this will fix my code?
...how to please! :)

Re: PHP to replace URL

Posted: Sat Sep 26, 2009 6:13 am
by jackpf

Code: Select all

<?php echo $SITE_URL;?>

Re: PHP to replace URL

Posted: Sat Sep 26, 2009 6:42 am
by jmaker
Maybe he was going for this?

Code: Select all

 
<?=$SITE_URL?>
 

Re: PHP to replace URL

Posted: Sat Sep 26, 2009 6:54 am
by wayneob
Thanks! :)

works without the config!

Code: Select all

<?php echo $SITE_URL;?>

Solved!

Re: PHP to replace URL

Posted: Sat Sep 26, 2009 9:03 am
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