Archive for the ‘ PHP ’ Category

I get asked quite often if there is a way to show CODE on a website, with it’s formatting in place?

The short answer is <pre>

It can output free text (i.e. non server side code) in a pre-formatted way. Yep, PRE = Pre-formatted.

On top of that, Preformatted also renders the php print_r() output in a nicely nested unordered list, which is great for debug purposes;

e.g.   echo “<pre>”;    print_r($arr);  echo “</pre>”;

I am sure there are other uses for the <pre> tag too, I have just scratched the surface.

Give it a go – let me know if you find other uses for it.

Thanks.

These settings are a web developers worst nightmare…. what happens if a web browser ignores the website FONTS? or worst still the STYLESHEETS?

Well – i guess if the website is built with accessibilty in mind, then there is no problem;

The page will render correct, no matter what browser or platform… but… if you have to use absolute positioning, and specific font sizes… then please please bear these settings in mind.

IE7 Accessibility Options

Tools | Internet Options | Accessibility.

Happy coding people!

Whilst working on an E-commerce website, written in PHP i came across and issue where i had a price stored in a table as a float.

I wanted to split the pounds, and pence into two variables to make it easier to work with, but then save the results back into 1 field. So this is what i did.

————–

http://uk2.php.net/manual/en/function.explode.php#63110
If you want to split a price (float) into pounds and pence.

or dollors and cents etc etc.

$price = "6.20";

$split = explode(".", $price);
$pound = $split[0]; // piece1
$pence = $split[1]; // piece2

echo "&pound $pound . $pence\n";

————-

Enjoy :)

Website Copyright Date

Have you noticed that some websites have a copyright date which is wrong?

For example:

www.somecompany.com (I appologise if you own this site)

then on the site, you have, Copyright SomeCompany Ltd 2002-2006

Now, if your lucky, your site is designed so that the footer can be changed once, so the entire site is updated. Well done.
For the others… shame on you. – Redesign your site.

Anyway.. heres a way to crack it on the head once and for all.

PHP
2003 - < ?php echo date("Y"); ?>
ASP
2003 - < %= year %>   

This way, as long as your server date is correct, your website will always be up to date. In fact, consider using date more in this way, to save yourself manual intervention.