Pure JS - Display Time Elapsed & Remaining
- Category: JavaScript
- Hits: 3684
This is an example of Javascript code to update and display the elapsed/remaining hours minutes and seconds in real-time.
Why?
I know there are a lot of articles out there that write about the same, but this is an example that I was coding and found to be one of the most reduced cut down formats I've made. I thought I'd make a note of it to not have to search elsewhere...
This example specifically displays the time remaining on an access_token which is generated from an OAuth 2.0 process. I want to display to the user how much time is left before another access token will be generated and how long ago was the last token created.
How?
So almost pure JS. I'm working out the seconds remaining and seconds elapsed in PHP first then passing these as two variables to the below code but you could get your values from anywhere:
Inline Labels in Form Fields using Javascript
- Category: JavaScript
- Hits: 8588
This is to describe how to change the value of a field of a form from it's default when it is clicked on so that it auto-clears and changes to how it normally works.
Example?
Note the value in the below field. Now click on it and it disappears, allowing you to type normally. Clear whatever you type so the field is empty and click somewhere on the page (not on a link as this will take you to another page) and the field returns to displaying "Name:".
Why?
I've noticed a lot of solutions now use JQuery or Mootools but most of these will not work in Internet Explorer 7 which is unfortunately still in use. I needed a back-to-basics solution and this is the one I have used since my fad of JavaScript 1.2 in the 90s. For broader compatibility, this is my recommended solution.
Slideshow div layer through a window
- Category: MooTools Framework
- Hits: 8967
What?
This article is a quick note to myself on the idea of a slideshow with the MooTools javascript framework. Basically, I want to create a div layer that I can see through (like a window with no glass) and for all the flashy stuff, to only appear within the boundary of the parent div layer.
Why?
I'm making a slideshow from scratch.
How?
The idea is:
Mootools - How to contain a menu sidebar between header and footer
- Category: MooTools Framework
- Hits: 7995
This has taken me too long to figure out and I hope I don't lose this note again. The only website that was titled similarly kept slowing down my computer too much so I decided to work out my own. The complexity is due to content also being dynamically resized in height.
What?
Basically I have a menu in a sidebar, I don't want it to overlap the header nor the footer.I have a content page next to it which changes in height dynamically (a separate mootool function to this one).
How?
PHP Issue: simplexml_load_string parser error : Input is not proper UTF-8, indicate encoding !
- Category: Personal Home Page
- Hits: 9464
What?
A quick article to stop me running into this issue again. This article serves to address the issue of importing characters from an XML in a different language character set and trying to load it in PHP with the function simplexml_load_string(). The error I get is something similar to:
PHP Warning:
simplexml_load_string(): Entity: line #: parser error : Input is not proper UTF-8, indicate encoding ! Bytes: 0xA0 0x3C 0x2F 0x73 in /home/public_html/my_folder/my_xml_processing_script.php on line 160
Why?
I'm downloading an XML feed to our servers, and then loading the downloaded file into memory with simplexml_load_string(). I get the above error when it is attempting to load an XML feed which is mostly in Spanish and breaks at the following XML node:
<baños>2</baños> -> yields issue: PHP Warning: simplexml_load_string(): <baños>2</baños> in /home/public_html/my_folder/my_xml_processing_script.php on line 160 should read <baños>2</baños>
How?
PHP - Remove newlines and spaces from StyleSheet
- Category: Personal Home Page
- Hits: 3853
What?
This is a quick note on how to reduce a whole bunch of CSS into a single line without unnecessary spaces and new lines.
Why?
What I have:
#copyright a{ margin: 10px 0 0 85px; box-shadow: 5px 5px 5px 0px rgba(51, 51, 51, 0.3); }
What I want:
#copyright a{margin:10px 0 0 85px;box-shadow:5px 5px 5px 0px rgba(51,51,51,0.3);}
How?
So I'm doing this with a regular expression to get rid of newlines:
$v_AppStyle = " #copyright a{ margin: 10px 0 0 85px; box-shadow: 5px 5px 5px 0px rgba(51, 51, 51, 0.3); }"; $v_AppStyleFormatted = preg_replace('/\s+/', ' ', $v_AppStyle);
and a few str_replace arrays:
// exceptions $a_ReplaceFrom1 = array("px ", "0 ", " a"); $a_ReplaceTo1 = array("px?", "0?", "?a"); $v_AppStyleFormatted = str_replace($a_ReplaceFrom1, $a_ReplaceTo1, $v_AppStyleFormatted); // replace all spaces to empty and replace question marks back to spaces $a_ReplaceFrom2 = array(" ", "?"); $a_ReplaceTo2 = array("", " "); $v_AppStyleFormatted = str_replace($a_ReplaceFrom2, $a_ReplaceTo2, $v_AppStyleFormatted); echo $v_AppStyleFormatted;
URL Alias uniqueness with PHP & MySQL
- Category: Personal Home Page
- Hits: 5702
So this is an article for me on how to copy Joomla's and Wordpress' feature where a Title/Name value is converted to a search-engine friendly URL alias and is unique in the database. Ok that's a long sentence; let me try this:
- When I save a record in JoomlaCMS or WordpressCMS
- It creates a unique name to use in URLs
- I want that
Why?
These are used as inputs to server-side scripts for the sake of search-engine friendliness. There are no silver bullets here but I want to block any character that isn't a letter, a number or an underscore.
How?
Suppose the following exists as a MySQL database table called my_table_name:
What we have:
/----------|-------------------|----------------------\ | id | name | url_alias | |----------|-------------------|----------------------| | 1 | My *First* Test | my_first_test | | | | | | | | | \----------|-------------------|----------------------/What we want:
/----------|-------------------|----------------------\ | id | name | url_alias | |----------|-------------------|----------------------| | 1 | My *First* Test | my_first_test | | 2 | My *First* Test | my_first_test_1 | | 3 | My _-_First Test | my_first_test_2 | \----------|-------------------|----------------------/
Convert Past Date to Time Ago in PHP
- Category: Personal Home Page
- Hits: 5984
Just a quick note to refine a function that will take a date in the past and return the number of years, months, weeks, days, hours, minutes and seconds.
Why?
Here are some examples of what we want to achieve:
1 year 2 months 3 weeks 4 days 5 hours 6 minutes 7 seconds // full string 1 year 3 weeks 5 hours 7 seconds // where shown values are not zeroActually we just want the first two words of those strings:
3 days ago // where event is 3 days ago or just over but less than 4 days ago 1 week ago // where event is just over 1 week ago but less than 2 weeks ago
How?
Page 6 of 9
Credit where Credit is Due:
Feel free to copy, redistribute and share this information. All that we ask is that you attribute credit and possibly even a link back to this website as it really helps in our search engine rankings.
Disclaimer: Please note that the information provided on this website is intended for informational purposes only and does not represent a warranty. The opinions expressed are those of the author only. We recommend testing any solutions in a development environment before implementing them in production. The articles are based on our good faith efforts and were current at the time of writing, reflecting our practical experience in a commercial setting.
Thank you for visiting and, as always, we hope this website was of some use to you!
Kind Regards,
Joel Lipman
www.joellipman.com
Latest Articles
Accreditation

