Reply to Re: Change included code

Your name:

Reply:


Posted by Jerry Stuckle on 04/19/07 13:41

Jon Slaughter wrote:
> <german.rumm@gmail.com> wrote in message
> news:1176958924.412049.59540@b58g2000hsg.googlegroups.com...
>>>>>>>> Index.php is basically an html file uses a linked css file and when
>>>>>>>> its
>>>>>>>> included in the new file its referencing a css file in the wrong
>>>>>>>> spot.
>>>>>>>> I need to add "../" to the css file reference in Index.php to make
>>>>>>>> it
>>>>>>>> work.
>> If index.php is HTML file (no parsing needed), you can "include" by
>> calling
>> <?php echo file_get_contents('../index.php'); ?>
>> to modify path, simply use str_replace or RegExp on
>> file_get_contents() return value, like so:
>> <?php echo str_replace('path/to/stylesheet.css', 'new/path/to/
>> stylesheet.css', file_get_contents('../index.php'); ?>
>>
>> But it's really more clever to use absolute paths.
>>
>
> using
>
> <LINK REL=StyleSheet HREF="/Styles/Main.css" TYPE="text/css">
>
> instead of
>
> <LINK REL=StyleSheet HREF="Styles/Main.css" TYPE="text/css">
>
> doesn't work when I do not include the the html file from a directory that
> contains Styles/Main.css.
>
> For some reason the absolute paths are not working. The browser is trying
> not looking from the root but always from the current dir.
>
> using code to change link still doesn't work
>
> echo str_replace('"/Styles/Main.css"', '"/../Styles/Main.css"',
> file_get_contents('../Main.php'); );
>
> It does change the link properly but no matter what I use it does not find
> the css file(I've tryed /.. and ../ but nothing works).
>
>
> The directories are right but I can't seem to get the style sheet.
>
>

Of course. "../Main.php" is a request to the webserver to fetch a file
one level below the root directory - which is not accessible to outside
requests.

And this is the crappiest way to go - see my note above about it
requiring a lot of additional and unnecessary work on the webserver.

Your problem is not the code. It's your screwed up test environment.
Straighten that out and it will work.

You're using a hammer to drive in a screw. And when that doesn't work,
you're trying a bigger hammer.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[Back to original 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

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