Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

using include to easily change short text through multiple..

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

using include to easily change short text through multiple..

Postby yankees230230 » Tue Aug 12, 2003 4:24 pm

hey i have a site and i want to easily be able to cange the copyright info on the bottom through about 30 pages... where the copyright should go i put this..
Code: Select all
<?php include 'http://www.happydogbehavior.com/html/home/copyright.txt' ?>


I also tried
Code: Select all
<?php include 'copyright.txt' ?>


neither of these work... the copyright.txt said Copyright 2003
nothing showed up..
yankees230230
New php-forum User
New php-forum User
 
Posts: 18
Joined: Fri Jul 11, 2003 1:44 pm

Postby swirlee » Tue Aug 12, 2003 5:44 pm

Assuming PHP is working correctly, then this is probably a path problem. Though you can specify a whole URL, assuming "URL fopen wrappers" are enabled (see the documentation), it's much faster to just use the path relative to the current working directory (e.g. where the currently-running PHP script resides). So, if copyright.txt is in the same directory as your page, the following will work fine:

Code: Select all
<?
   include 'copyright.txt';
?>


If it's somewhere else, though, you have to specify a relative path:

Code: Select all
<?
   // file in the parent directory:
   include '../copyright.txt';

   // file in a subdirectory:
   include 'subdir/copyright.txt';

   // file in a sibling directory
   include '../sibling/copyright.txt';
?>
User avatar
swirlee
Moderator
Moderator
 
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back

Postby yankees230230 » Thu Aug 14, 2003 11:49 am

i put
Code: Select all
<?
   include 'copyright.txt';
?>

didn't work... heres the link to the page...
http://www.happydogbehavior.com/html/home/index2.htm

and here is the text file...
http://www.happydogbehavior.com/html/home/copyright.txt

why isn't it working??????? thanks
yankees230230
New php-forum User
New php-forum User
 
Posts: 18
Joined: Fri Jul 11, 2003 1:44 pm

Postby swirlee » Thu Aug 14, 2003 12:52 pm

yankees230230 wrote:heres the link to the page...
http://www.happydogbehavior.com/html/home/index2.htm


Assuming you have PHP running on your server (you do, don't you?), you have to make sure PHP is actually processing the file. Most servers are set up to only process files with a .php (and sometimes .php3) extension, so if you name your file .htm, none of the PHP is going to get processed.

If you have access to, you can configure your server to parse .htm files as PHP, but it's smarter to just rename the file to .php.
User avatar
swirlee
Moderator
Moderator
 
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back

Postby yankees230230 » Sat Aug 23, 2003 3:34 pm

haha thanks.. worked beautifully ;)
yankees230230
New php-forum User
New php-forum User
 
Posts: 18
Joined: Fri Jul 11, 2003 1:44 pm

Postby Joel » Sat Aug 23, 2003 6:50 pm

Hey, I was just looking at your site and the hover images at the top were terrible!

Firstly, they are 12kb each - you should use GIF format for those and cut down the colours.

Secondly, you should be preloading the images.

Sorry if I sound arrogant, it's just one thing that annoys me - when images slow down the page too much. (I have 33.6)
Joel
New php-forum User
New php-forum User
 
Posts: 193
Joined: Sat Mar 29, 2003 11:57 pm
Location: Auckland, New Zealand

Postby swirlee » Sat Aug 23, 2003 7:29 pm

Joel wrote:Firstly, they are 12kb each - you should use GIF format for those and cut down the colours.


Joel is correct, but I disagree in one respect -- use PNG, not GIF. PNG, when used correctly, averages about 40% better compression.
User avatar
swirlee
Moderator
Moderator
 
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back

Postby Joel » Sun Aug 24, 2003 2:33 am

Yes, when used correctly.

Also I noticed the top image is 89kb, all one image. The site took very long to load on my computer. If your target audience is majorly with broadband internet then there ain't much problem, but otherwise there.
Joel
New php-forum User
New php-forum User
 
Posts: 193
Joined: Sat Mar 29, 2003 11:57 pm
Location: Auckland, New Zealand

Postby yankees230230 » Sun Aug 24, 2003 12:21 pm

I have been so concentraded on the backend i have forgotten about file size.. i am kinda spoiled here because i have a 1mb/s connect.

ok i tried tested the buttons and they come out too..
JPEG-12K PNG-4K GIF-4K
and the top bar is
JPEG-96K PNG-108K GIF-36K

The problem is when i make it a gif it gets a little fuzzy and i notice some horizontal lines... I think this is because the way a gif compresses right?

Also I am almost done with the site and It has about 40 Pages... is there away to change each button without going through all 40 and editing the code?

And lastly doesn't that java on the top preload the images? I used dreamweaver for that part and choose preload all rollovers.

Thanks for all your help!
yankees230230
New php-forum User
New php-forum User
 
Posts: 18
Joined: Fri Jul 11, 2003 1:44 pm

Postby swirlee » Sun Aug 24, 2003 12:56 pm

yankees230230 wrote:ok i tried tested the buttons and they come out too..
JPEG-12K PNG-4K GIF-4K
and the top bar is
JPEG-96K PNG-108K GIF-36K


This is where the "when used correctly" bit comes into play. I took your "Home" button, for example, and used PNG and got it down to 441 bytes (16 colors) without a discernable loss in quality.

Concerning the header image, you should break it up into two images, because while most of it will compress well with PNG, the photograph on the right should use JPEG (at a rather low compression because the background is going to be prone to visible artifacts). I got the left part down to ~15k (though it might need some more tweaking) at 128 colors and the right part down to ~7.6k at 15% compression, for a grand total of ~22.6k.

Mind you, these are only rough optimizations, and Fireworks or Photoshop might do a better or worse job (I use PSP 8).
User avatar
swirlee
Moderator
Moderator
 
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back

Postby yankees230230 » Sun Aug 24, 2003 6:18 pm

ok thanks.. i will try that with the png... Is there anyway easily to change them all to gif or png in all 40 of the pages without manually going through each page?
yankees230230
New php-forum User
New php-forum User
 
Posts: 18
Joined: Fri Jul 11, 2003 1:44 pm

Postby swirlee » Sun Aug 24, 2003 7:17 pm

yankees230230 wrote:Is there anyway easily to change them all to gif or png in all 40 of the pages without manually going through each page?


How many images do you have? If the navigation is basically the same on every page, you ought to have just a single set of images. It looks like you built it in Fireworks, so it doesn't seem like it should be too difficult to just export the whole lot again all at once.
User avatar
swirlee
Moderator
Moderator
 
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back

Postby Joel » Sun Aug 24, 2003 8:46 pm

If you are using the same images on each page then just changing the image will fix it, although you might have to rename your png's to whatever the file type was before, this shouldn't be too much of a problem for the browser as it still sends header information.

So you could have a PNG file - and then rename it to home.gif and you won't have to change any links to the images.

The preload is working on some of the images, but not all.

I got the home image to 341bytes - 8 colour GIF with no obvious compression. This was in Fireworks.
Joel
New php-forum User
New php-forum User
 
Posts: 193
Joined: Sat Mar 29, 2003 11:57 pm
Location: Auckland, New Zealand

Postby swirlee » Sun Aug 24, 2003 9:27 pm

Joel wrote:So you could have a PNG file - and then rename it to home.gif and you won't have to change any links to the images.


Ack! Don't do that. A file's extension should reflect its type. If you're using Dreamweaver, you can just do a find-and-replace on all of the files in the site.
User avatar
swirlee
Moderator
Moderator
 
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back

Postby yankees230230 » Mon Aug 25, 2003 12:46 pm

i think i will just change the name i don't really care if the extension properly reflects or not as long as it doesn't screw up functionality
yankees230230
New php-forum User
New php-forum User
 
Posts: 18
Joined: Fri Jul 11, 2003 1:44 pm

Postby swirlee » Mon Aug 25, 2003 12:48 pm

Ack! Just do find-and-replace, man! This is going to bite you in the ass later on.. Dreamweaver has a very nice Find and Replace tool that'll let you change all of those .jpgs into .pngs in one fell swoop.
User avatar
swirlee
Moderator
Moderator
 
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back

Postby yankees230230 » Mon Aug 25, 2003 1:03 pm

Ok i did the file extension name change for now and i got it down to a gif 256 colors and its 29k... certainly still not acceptable for you guys... I tried going lower but the dog on the left gets very pixilized. As well as the photo on the right. Anyway here it is... http://www.happydogbehavior.com/html/courses/ 29k is certainly much better than 85 ;) Now i just need to work on the other graphics Please tell me how changin the file extension can screw me later so i am aware...
yankees230230
New php-forum User
New php-forum User
 
Posts: 18
Joined: Fri Jul 11, 2003 1:44 pm

Postby swirlee » Mon Aug 25, 2003 1:17 pm

You could even chop it up into three images -- one PNG for the dog, one PNG for the middle, and one JPEG for the kids. The middle can be really low-color (32 or 64 should do fine), the dog on the left 128 or 256, and the kids on the right, maybe 15% compression (85% quality). This should be pretty trivial to do in Fireworks. If you don't like the "pixellation", just turn off dithering -- dithering is the enemy!
User avatar
swirlee
Moderator
Moderator
 
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back

Postby Joel » Mon Aug 25, 2003 1:19 pm

Ack!


Although, I don't see a problem in functionality for the file extension change. Maybe mister Swirlee will explain.
Joel
New php-forum User
New php-forum User
 
Posts: 193
Joined: Sat Mar 29, 2003 11:57 pm
Location: Auckland, New Zealand

Postby swirlee » Mon Aug 25, 2003 2:47 pm

It isn't a problem with functionality (well, that's not entirely true, but for the most part), it's a issue of convention and organization. Will you remember a year from now that those files are GIFs and not JPEGs? What if you hire someone a year from now to work on the web site and they just look at the extension (it's my experience that most graphics programs won't tell you if the extension is wrong unless you do some digging) and save as JPEG instead of GIF? You're back in the same situation you were before. Extensions were implemented in the first place to give humans (not the machines they're using) an idea of what kind of file a particular file is. When it's easy enough to just do a global find-and-replace, why mess with convention and stand the potential of confusing yourself or others or fouling things up a year down the road?
User avatar
swirlee
Moderator
Moderator
 
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back

Postby swirlee » Mon Aug 25, 2003 2:51 pm

Addendum:

Would you, Joel, just rename all of your PHP files to .html and tell Apache to parse them as PHP? Why not? The functionality is the same..
User avatar
swirlee
Moderator
Moderator
 
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back

Postby yankees230230 » Mon Aug 25, 2003 3:51 pm

y would i hire someone to work on the site... This is my first site I am bein paid for... :D I am 14 :wink:... unless i get really good and have to go through an expansion ;) In fall last year i didn't no what photoshop or html or php was... Now I am workin on mysql so i am moving along slowly but surely :o
yankees230230
New php-forum User
New php-forum User
 
Posts: 18
Joined: Fri Jul 11, 2003 1:44 pm

Postby swirlee » Mon Aug 25, 2003 5:18 pm

Well, it's a very thoughtfully-designed site and if you're doing stuff like this at age 14, you'll no doubt have taken over the world by 25. I'll make sure and try to stay on your good side. :)
User avatar
swirlee
Moderator
Moderator
 
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back

Postby tryton » Mon Aug 25, 2003 7:35 pm

Wow, 14. Makes me wish I would have stayed in the house instead of playing basketball.

Ironically, a friend of mine just got paid $175,000 for building a website (took him a whole year to develop this website). Maybe something you want to aspire for yankee.This guy also works with Acclaim and some other companies as a game reviewer. He's one of those guys that stays in the house for hours playing Half-Life.

But I do have many questions, which I will start in a new thread. *Death to thread jacking*
User avatar
tryton
New php-forum User
New php-forum User
 
Posts: 49
Joined: Wed Jul 09, 2003 8:25 am
Location: Joze

Postby yankees230230 » Mon Aug 25, 2003 7:54 pm

Wow, 14. Makes me wish I would have stayed in the house instead of playing basketball.

Lol... Thats the thing.. i really try to balance my time good... I don't like staying on the computer the whole day... I usually work from 11pm-3am ;) And this year I also got hired by my school to help set up networking. How old is your friend??
yankees230230
New php-forum User
New php-forum User
 
Posts: 18
Joined: Fri Jul 11, 2003 1:44 pm

Next

Return to PHP coding => General

Who is online

Users browsing this forum: yetticaretti and 3 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.