You are here: Re: phpscript changing relatives path by absolute. « PHP Language « IT news, forums, messages
Re: phpscript changing relatives path by absolute.

Posted by shimmyshack on 02/22/07 18:12

On 22 Feb, 18:10, "shimmyshack" <matt.fa...@gmail.com> wrote:
> 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

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/'

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация