Home > Archive > PHP Language > February 2007 > phpscript changing relatives path by absolute.
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
phpscript changing relatives path by absolute.
|
|
| Alred Wallace 2007-02-20, 6:58 pm |
| Does anybody knows where i can find a phpscript making all link in a web
page (http://thehost/thepage.html) absolute:
images, script, styles, href...
images being the most important:
src=http://hosturl...
replacing <img src="../imzgd/sdf/myimage.jpg".. in thepage.html. source.
I think it can be done with regular expression, but i much prefer to find
something more "complete" and unbugy.
Thk for your help.
| |
|
| On 21 Feb, 00:55, "Alred Wallace" <p...@free.Fr> wrote:
> Does anybody knows where i can find a phpscript making all link in a web
> page (http://thehost/thepage.html) absolute:
> images, script, styles, href...
>
> images being the most important:
> src=http://hosturl...
> replacing <img src="../imzgd/sdf/myimage.jpg".. in thepage.html. source.
see the discussion for the realpath function on the PHP documentation
site.
C.
| |
| shimmyshack 2007-02-22, 6:59 pm |
| On 21 Feb, 00:55, "Alred Wallace" <p...@free.Fr> wrote:
> Does anybody knows where i can find a phpscript making all link in a web
> page (http://thehost/thepage.html) absolute:
> images, script, styles, href...
>
> images being the most important:
> src=http://hosturl...
> replacing <img src="../imzgd/sdf/myimage.jpg".. in thepage.html. source.
>
> I think it can be done with regular expression, but i much prefer to find
> something more "complete" and unbugy.
>
> Thk for your help.
in what context?
1. opening a prewritten webpage, parsing it for relative links and
correcting them
2. or within a php script so that you can write your links in the form
1.
$html .= '<img src="' . IMAGES_ROOT . 'myimage.jpg" />';
this is best done with a regular expression, and will have already
been done by someone else, you will have to parse for HREF, SRC,
URL( with single and double quotes, perhaps javascript,
2.
if the latter, then a very useful method is to have a config.inc.php
file which has all your paths set inside it when you install the app,
or on a per request basis.
$arrConfig['selected_theme'] = 'big_brash_blue_design';
define( FS_APP_ROOT, dirname( __FILE__ ) );
define( WEB_APP_ROOT, str_replace( FS_APP_ROOT, '',
dirname($_SERVER['REQUEST_URI']) . '/' ) );
define( WEB_THEMES_ROOT, WEB_APP_ROOT . 'themes/' .
$arrConfig['selected_theme'] . '/' );
define( WEB_IMAGES_ROOT, WEB_THEMES_ROOT . '/images/' );
echo '<pre>' , FS_APP_ROOT, "\n", WEB_APP_ROOT, "\n", WEB_THEMES_ROOT,
"\n", WEB_IMAGES_ROOT , '</pre>';
where some of the configs can be chosen from a selection and stored as
a user preference in a cookie... as in the case of the theme here
This way your environment is set up, and whenever you have a
| |
| shimmyshack 2007-02-22, 6:59 pm |
| On 22 Feb, 18:10, "shimmyshack" <matt.fa...@gmail.com> wrote:
> On 21 Feb, 00:55, "Alred Wallace" <p...@free.Fr> wrote:
>
>
>
>
>
> in what context?
> 1. opening a prewritten webpage, parsing it for relative links and
> correcting them
> 2. or within a php script so that you can write your links in the form
>
> 1.
> $html .= '<img src="' . IMAGES_ROOT . 'myimage.jpg" />';
> this is best done with a regular expression, and will have already
> been done by someone else, you will have to parse for HREF, SRC,
> URL( with single and double quotes, perhaps javascript,
>
> 2.
> if the latter, then a very useful method is to have a config.inc.php
> file which has all your paths set inside it when you install the app,
> or on a per request basis.
>
> $arrConfig['selected_theme'] = 'big_brash_blue_design';
> define( FS_APP_ROOT, dirname( __FILE__ ) );
> define( WEB_APP_ROOT, str_replace( FS_APP_ROOT, '',
> dirname($_SERVER['REQUEST_URI']) . '/' ) );
> define( WEB_THEMES_ROOT, WEB_APP_ROOT . 'themes/' .
> $arrConfig['selected_theme'] . '/' );
> define( WEB_IMAGES_ROOT, WEB_THEMES_ROOT . '/images/' );
>
> echo '<pre>' , FS_APP_ROOT, "\n", WEB_APP_ROOT, "\n", WEB_THEMES_ROOT,
> "\n", WEB_IMAGES_ROOT , '</pre>';
>
> where some of the configs can be chosen from a selection and stored as
> a user preference in a cookie... as in the case of the theme here
>
> This way your environment is set up, and whenever you have a
I got my 1. a line or two too early, I meant that the first method was
best using reg exp, the line of php should go with the 2nd method :)
and theres a mistake in '/images/' at the end it should be 'images/'
|
|
|
|
|