So I’ve got myself some work on a new website for my boss this week, and part of his site currently has some sort of slideshow thing – using jQuery. I have used them before, but never actually got round to coding one. So I decided to stop being lazy, and actually look at coding something up. So here it is:
It is obviously lacking proper HTML structure, however, as it is, it works. Ultimately you created an element containing a series of images, and then simply invoke the slideshow function on the element. Make sure that the element container has an id as it is used to refer to the slideshow items later.
jQuery is required for this, so ensure that you are including the JavaScript file when using this code.
So as part of my current work, I have to export customer information, orders and order details for importing into Sage. Also, product information has to be exported for Google shopping. Both of these are being exported in XML. Instead of writing out all of the coding and causing problems etc. I bodged together a simple function – it is by no means perfect:
function createXML($x, $y){
}
So for this project that I’m working on, I have to be able to format a number to be comma separated and decimalised (only if the decimal numbers aren’t 00) to two decimal places (with rounding – when there is 3 or more decimal places). So, unfortunately there isn’t any actual predefined function out there for any of this. So through the Math.round(), Math.pow() and String.replace() functions, I managed to cobble something together that works flawlessly:
}
function formatPrice(x){
while(/(\d+)(\d{3})/.test(x[0]))
return x[0] + x[1];
Just to show what it does, here is some testing that I did with the code. Original number on the left, new number on the right:
1000 -> 1,000
1000.1 -> 1,000.10
1000.00 -> 1,000
0.00 -> 0
0.1 -> 0.10
0.10 -> 0.10
1000.1236123 -> 1,000.12
1000.1276123 -> 1,000.13
So, one of my friends asked me a moment ago whether it was possible to have a page named “rawr.james” and have it parse in the same way as “rawr.php”. Quick searching shows that it’s possible through one simple line of .htaccess:
AddType application/x-httpd-php .james
Of course, you can change the “.james” to whatever extension you want. Just save the file as .htaccess and upload to your server.
So many people are now developing websites that like to deliver specific content if you are viewing from an iPhone or iPod Touch. This can be done using a small snippet of coding that checks the HTTP_USER_AGENT of the browser.
strpos($_SERVER['HTTP_USER_AGENT'], "iPhone");
This code could be used within a conditional statement such as:
<?php
if (strpos($_SERVER['HTTP_USER_AGENT'], "iPhone"))
echo 'You are using an iPhone';
else
echo 'You are not usnig an iPhone';
?>