Validate Email Address in Javascript

Below is a nice little Javascript RegularExpression to validate email addresses. /^\w.+@[a–zA–Z_.]+?\.[a–zA–Z.]{2,3}$/ ..and to use it.. if (/^\w.+@[a-zA-Z_.]+?\.[a-zA-Z.]{2,3}$/.test(email)) alert("Success"); else alert("Fail");

Read more
Remove hash from window.location in Javascript

E.g. URL: http://example.com/?option=1&task=2&listing_id=36&layout=4&table=5#some_hash_value_here So how would you get the current URL using Javascript? That is really easy, you can use window.location.href or just simply window.location. But how do you replace the #hash at the end if it exists? That too is quite easy, you can just do something like this: window.location.href.split("#")[0] or window.location.href.substr(0, window.location.href.indexOf("#")) So […]

Read more
URL GET vars to PHP Array

Sometimes you will need to retrieve the GET variables passed into the current page URI or you will have a URL string to work from which contains certain GET variables, the below method helps a lot to convert them into an array which you can easily manipulate later. $url = $_SERVER["REQUEST_URI"]; parse_str(parse_url($url, PHP_URL_QUERY), $array); `$array` […]

Read more
Remove specific HTML tags using PHP

There are times when you want to remove a specific HTML tag from an HTML block of text. This could be an anchor(<a/>>) or an image(<img/>) perhaps. You can use preg_replace to do this quite quickly and efficiently. Remove an anchor: $content = "Sample text <a href=’#’>Our anchor</a>. Etc etc"; $content = preg_replace(‘/<\/?a[^>]*>/’,”,$content); //$content is […]

Read more
Keep Google Map v3 centered when browser is resized

Using Google Maps V3 Javascript API you can keep the map centered to the browser’s window by using the following trick when resizing the window. var mapOptions = {     zoom: 2,     center: new google.maps.LatLng(0,0), mapTypeId: google.maps.MapTypeId.ROADMAP }; var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions); // this is our gem google.maps.event.addDomListener(window, "resize", function() […]

Read more
Buy a Google Nexus 10 in the UK!

If you are looking to get a Google Nexus 10 inch tablet and are based in the UK you are in for a shocker! The only place to buy it is at the Google Play store and since about the middle of November 2012 they have been sold out. Some people say it’s due to […]

Read more
Let Joomla and MySQL interact!

I often need a quick and easy few lines to retrieve some data from MySQL using Joomla without all the MVC nonsense that usually goes about this topic. So here is how I do it! $dbSEL = JFactory::getDbo(); $dbSEL->setQuery("SELECT MAX(`start_price`) FROM #__some_table"); $dbSEL->query(); echo $dbSEL->fetchRow(); As you can see above, we get the current database […]

Read more
Perform a Mysql Query using Joomla!

This is really actually meant for future reference for myself as lately I’ve been doing quite a lot of Joomla! mysql coding and have used the following code just short of 3million times. $db = JFactory::getDbo(); $querySelectId = "SELECT `id` FROM #__some_table WHERE `user_id`=’$user_id‘"; $db->setQuery($querySelectId); $db->query(); $data = $db->loadAssoc(); What we do in the above […]

Read more
Refresh User Data in Joomla

I was busy with a custom component in Joomla, and it stored it’s own user_details based off of the main users table, but if the details were changed then I needed the system to update the session to reflect the changes. This is what I did: $user = JFactory::getUser(); $session = JFactory::getSession(); $session->set("user", new JUser($user->id)); […]

Read more