Re: [PHP] Re: help condensing regular expressions

2002-04-06 Thread Tom Rogers

Hi
I have never used .htaccess but I'll read up on it, I am the ISP so it 
won't be a problem :)

Tom

At 06:12 PM 6/04/2002, Chris Adams wrote:
In article [EMAIL PROTECTED], Tom
Rogers wrote:
  Thats what I was after :)

Glad I could help.

  At the top of each page I now do
 
  $reltoroot = preg_replace(|/[^/]+|, ../, 
 dirname($_SERVER['PHP_SELF']));
  ini_set 
 (include_path,ini_get(include_path).:.$reltoroot.../include);
 
  which takes care of the include path

Out of curiosity, couldn't you put something like
php_value include_path .:/document/root/include:/usr/lib/php

in a .htaccess file? Or has your ISP disabled .htaccess files?

Chris

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Re: help condensing regular expressions

2002-04-05 Thread Tom Rogers

Hi
Yes that would be fine for the html examples I gave but the real use is for 
php to find the include directory which I keep out of the server tree, one 
directory back like this

include($relative_root.../include/mysql_connect.inc)

Each domain has its own include directory which I want to keep seperate 
from the default php include directory set in php.ini

The other thing is that this gets rid of the include file inside included 
file problem as long as I set $relative_root at the top level.
Tom

At 06:26 AM 6/04/2002, Julio Nobrega Trabalhando wrote:
   How about:

$site_root = '/www/user/htdocs/';

img src=?php echo $site_root; ?images/logo.png /

   Instead of going relative, go from the root. Or you could put $site_root
as your url:

$site_root = 'http://www.your_site.com/';

--

Julio Nobrega.

Um dia eu chego lá:
http://sourceforge.net/projects/toca

Ajudei? Salvei? Que tal um presentinho?
http://www.submarino.com.br/wishlistclient.asp?wlid=664176742884


Tom Rogers [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
  Hi
  I am trying to calculate how far into a directory structure I am so that I
  can include images and include files without having to hard code them.
  I need to turn $PHP_SELF which could be /admin/emails/index.php into
../../
  which I can then use to get to any directory from root.
  like IMG src=?echo $relative_root?images/logo.png
  Regular expressions leave me cold but I have come up with the following
  monster which works
 
  $relative_root = preg_replace(\/[[:alnum:]]+,../,
  preg_replace(/[[:alnum:]]+$,,strtok($PHP_SELF,.)));
 
  Anybody have a better solution?
  Thanks for any help.
  Tom
 



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] Re: help condensing regular expressions

2002-04-05 Thread Collins, Robert

why not use somthing like this then

include($DOCUMENT_ROOT./include/mysql_connect.inc);


Robert W. Collins II 
Webmaster 
New Orleans Regional Transit Authority 
Phone : (504) 248-3826 
Email : [EMAIL PROTECTED] 



-Original Message-
From: Tom Rogers [mailto:[EMAIL PROTECTED]]
Sent: Friday, April 05, 2002 2:33 PM
To: [EMAIL PROTECTED]
Subject: Re: [PHP] Re: help condensing regular expressions


Hi
Yes that would be fine for the html examples I gave but the real use is for 
php to find the include directory which I keep out of the server tree, one 
directory back like this

include($relative_root.../include/mysql_connect.inc)

Each domain has its own include directory which I want to keep seperate 
from the default php include directory set in php.ini

The other thing is that this gets rid of the include file inside included 
file problem as long as I set $relative_root at the top level.
Tom

At 06:26 AM 6/04/2002, Julio Nobrega Trabalhando wrote:
   How about:

$site_root = '/www/user/htdocs/';

img src=?php echo $site_root; ?images/logo.png /

   Instead of going relative, go from the root. Or you could put $site_root
as your url:

$site_root = 'http://www.your_site.com/';

--

Julio Nobrega.

Um dia eu chego lá:
http://sourceforge.net/projects/toca

Ajudei? Salvei? Que tal um presentinho?
http://www.submarino.com.br/wishlistclient.asp?wlid=664176742884


Tom Rogers [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
  Hi
  I am trying to calculate how far into a directory structure I am so that
I
  can include images and include files without having to hard code them.
  I need to turn $PHP_SELF which could be /admin/emails/index.php into
../../
  which I can then use to get to any directory from root.
  like IMG src=?echo $relative_root?images/logo.png
  Regular expressions leave me cold but I have come up with the following
  monster which works
 
  $relative_root = preg_replace(\/[[:alnum:]]+,../,
  preg_replace(/[[:alnum:]]+$,,strtok($PHP_SELF,.)));
 
  Anybody have a better solution?
  Thanks for any help.
  Tom
 



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] Re: help condensing regular expressions

2002-04-05 Thread Tom Rogers

Hi
For some reason $DOCUMENT_ROOT always points to /usr/local/apache/htocs 
even when the actual document root on the virtual domain is 
/usr/local/apache/domains/domain.com/www/
You can use PATH_TRANSLATED but that doesn't solve the http side when you 
may need to find the images directory from an included file :)
My little relative_root does the trick nicely for both situations, just I 
think the expression I use is very brutal and there is probably a more 
elegant way to arrive at the same result.
Tom

At 06:32 AM 6/04/2002, Collins, Robert wrote:
why not use somthing like this then

include($DOCUMENT_ROOT./include/mysql_connect.inc);


Robert W. Collins II
Webmaster
New Orleans Regional Transit Authority
Phone : (504) 248-3826
Email : [EMAIL PROTECTED]



-Original Message-
From: Tom Rogers [mailto:[EMAIL PROTECTED]]
Sent: Friday, April 05, 2002 2:33 PM
To: [EMAIL PROTECTED]
Subject: Re: [PHP] Re: help condensing regular expressions


Hi
Yes that would be fine for the html examples I gave but the real use is for
php to find the include directory which I keep out of the server tree, one
directory back like this

include($relative_root.../include/mysql_connect.inc)

Each domain has its own include directory which I want to keep seperate
from the default php include directory set in php.ini

The other thing is that this gets rid of the include file inside included
file problem as long as I set $relative_root at the top level.
Tom

At 06:26 AM 6/04/2002, Julio Nobrega Trabalhando wrote:
How about:
 
 $site_root = '/www/user/htdocs/';
 
 img src=?php echo $site_root; ?images/logo.png /
 
Instead of going relative, go from the root. Or you could put $site_root
 as your url:
 
 $site_root = 'http://www.your_site.com/';
 
 --
 
 Julio Nobrega.
 
 Um dia eu chego lá:
 http://sourceforge.net/projects/toca
 
 Ajudei? Salvei? Que tal um presentinho?
 http://www.submarino.com.br/wishlistclient.asp?wlid=664176742884
 
 
 Tom Rogers [EMAIL PROTECTED] wrote in message
 [EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
   Hi
   I am trying to calculate how far into a directory structure I am so that
I
   can include images and include files without having to hard code them.
   I need to turn $PHP_SELF which could be /admin/emails/index.php into
 ../../
   which I can then use to get to any directory from root.
   like IMG src=?echo $relative_root?images/logo.png
   Regular expressions leave me cold but I have come up with the following
   monster which works
  
   $relative_root = preg_replace(\/[[:alnum:]]+,../,
   preg_replace(/[[:alnum:]]+$,,strtok($PHP_SELF,.)));
  
   Anybody have a better solution?
   Thanks for any help.
   Tom
  
 
 
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Re: help condensing regular expressions

2002-04-05 Thread Tom Rogers

Thanks Chris
Thats what I was after :)
At the top of each page I now do

$reltoroot = preg_replace(|/[^/]+|, ../, dirname($_SERVER['PHP_SELF']));
ini_set (include_path,ini_get(include_path).:.$reltoroot.../include);

which takes care of the include path

I use the path translated info for pages that are sym linked across virtual 
domains such as admin pages.
Thanks again
Tom

At 03:49 PM 6/04/2002, Chris Adams wrote:
In article [EMAIL PROTECTED], Tom
Rogers wrote:
  I am trying to calculate how far into a directory structure I am so that I
  can include images and include files without having to hard code them.
  I need to turn $PHP_SELF which could be /admin/emails/index.php into 
 ../../
  which I can then use to get to any directory from root.

Here's a more compact regexp:

preg_replace(|/[^/]+|, ../, dirname($_SERVER['PHP_SELF']));

dirname() returns only the directory part of a filename (e.g. /~chris
from /~chris/myfile.php).

Using | instead of the usual / to delimit the regular expression just
saves a bit of typing.

(Note that for includes, you'd be better off setting include_path in
php.ini or .htaccess - that avoids the need to worry about where the
files are physically located)

If you need the local file path and you're using Apache, the
PATH_TRANSLATED variable can tell you where your files are:
$current_dir = dirname($PATH_TRANSLATED) . /;

This could be used to construct absolute paths internally - I use it in
my photo gallery code when creating thumbnails  such with convert.
Using it with DOCUMENT_ROOT can help if you need to construct things
like directory listings.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Re: help condensing regular expressions

2002-04-05 Thread Chris Adams

In article [EMAIL PROTECTED], Tom
Rogers wrote:
 Thats what I was after :)

Glad I could help.

 At the top of each page I now do
 
 $reltoroot = preg_replace(|/[^/]+|, ../, dirname($_SERVER['PHP_SELF']));
 ini_set (include_path,ini_get(include_path).:.$reltoroot.../include);
 
 which takes care of the include path

Out of curiosity, couldn't you put something like
php_value include_path .:/document/root/include:/usr/lib/php

in a .htaccess file? Or has your ISP disabled .htaccess files?

Chris

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php