1. Dynamic CSS without using JavaScript

    Let’s say you want some dynamic graphics on your website, but you don’t want to, or don’t know how to use JavaScript.

    Well PHP might be the answer. The first thing I thought was, ‘How do a I get PHP into my CSS File?’. Well you don’t!

    Inline CSS - most people hate it, but in this case, it can be useful.

    <style>

    #testdiv {

    height: 50px;

    background-color: red;

    <?php

    echo “width: ” . 250 . “px;”

    }

    </style>

    Stick that in your <head></head> tags, and PHP will write the width command for you! Now this is a very, very simple example, but use your imagination, and you’d be surprised what you can do!

  2. Embed Twitter In Your Website

    Recently Twitter has become the main outlet for Social Media on the Web, so it’s only logical that people want to embed twitter on their personal websites.

    But what if you are one of those people who doesn’t want a nasty Widget on their site? Well here is the solution to embed twitter fast - 1 line of PHP:

    <?php             

    echo simplexml_load_file(“http://twitter.com/statuses/user_timeline/yourusername.xml?count=1”)->status->text;                       

    ?> 

    It’s really that easy! Simply substitute your username into the PHP to embed twitter into your website!

    There are three small points to make though.

    1. If you have your Twitter feed set to private, you won’t be able to embed twitter.
    2. You will have to change your webpage to .php instead of .html. … OR
    3. You need to have a ‘.htaccess’ file in your root folder (where you store your website). Otherwise rename your file with .php at the end instead of .html.

    Check out this post on how to create a ‘.htaccess’ file if you don’t already know.

    Thanks to @mikevanis and @hellopablo for help on how to embed twitter.

    And that is how you embed twitter on your website.

    Happy Tweeting!

    Finlay

    ps…Use this on your site? Leave a comment below and tell me how you got on!

  3. Adding a ‘.htaccess’ File To Your Website

    Now let me just start by saying I am no expert in Web Development, or programming for that matter. But I know a nice piece of code when I see it!

    It was when I was experimenting with PHP that I learnt about the power of SimpleXML, and immediately thought how useful that could be for Twitter. So I wrote one line of code that would embed your latest Tweet in your website. 

    To get that working you need a ‘.htaccess’ file. Essentially this files let you run PHP script inside your HTML/XHTML Webpages.

    1. Create a new file names ‘.htaccess’ (without the inverted commas) in your favorite text editor.
    2. Put this line of code in that file, save, and close the file ‘AddType application/x-httpd-php .html .htm .xhtml’
    3. Upload this to your Web Host, into your root folder (the folder where your website lives)

    Hurray! Your ‘.htaccess’ file should now be up and running! If in doubt, contact your webhost.

    I take no responsibility if this does anything nasty to your website, so on your head be it! (But it really shouldn’t!)

    Enjoy!

    Finlay