After a last minute request to change a website so it automatically scrolls down to show Google Map when a search is submitted I was preparing to write some tacked on jQuery to provide the functionality. That was until I came across a Javascript function which already did exactly what I wanted, ScrollIntoView(). Continue reading “Javascript: ScrollIntoView()”
Getting File Extension Using PHP
Quick post, more as a reference for myself, of how to get the extension of a file using PHP.
Discovered a great post on Cowburn.info outlining the various ways to do this and the time implications, ending up with:
$filename = 'mypic.gif';
$ext = pathinfo($filename, PATHINFO_EXTENSION);
being the best option. Continue reading “Getting File Extension Using PHP”
Modx Evo eForm Throws Constant Validation Error On Select Options Created Using Snippet
Having to add a new form to an old Modx Evo site threw up a bug with the eForm add on today, when submitting the form I was constantly told I had an ‘Invalid Data Error’ on my dropdown field. Continue reading “Modx Evo eForm Throws Constant Validation Error On Select Options Created Using Snippet”
Using RegEx To Determine If Search Query Is A Postcode/Partial Postcode
Working on a site which asks users to enter a “place name, area or postcode” to search by, niggly problem where searching for postcode “OX2” for example, not only returned properties in OX2, but also in OX29. Continue reading “Using RegEx To Determine If Search Query Is A Postcode/Partial Postcode”
Friendly url’s giving a 404 error even though mod_rewrite is installed
When transferring a ModX site across to a newly setup cloud server I could only see the home page. After running through the ModX setup process again to get the manager’s file paths aligned correctly I checked through all the possible causes of this problem in the System Settings. Still no joy, all i got was a “File not found”. Continue reading “Friendly url’s giving a 404 error even though mod_rewrite is installed”
Hiding an entire site from robots
I don’t think i’ve ever had to hide an entire site from search engines before, so today I learnt something new that saves a lot of time.
Rather than writing a complex robots.txt file you simply add the following line of code to your page <head>
<meta name="robots" content="noindex">
Simples. Continue reading “Hiding an entire site from robots”
Mysql not found by PHP
In the middle of a Drupal install on my localhost I received the following error
No such file or directory (trying to connect via unix:///var/mysql/mysql.sock) i…
2AM and in need of a quick fix I just created an alias in the location PHP was looking for mysql.
1234 mkdir /var/mysqlln -s /tmp/mysql.sock /var/mysql/mysql.sock
Replacing accented character with it’s standard character in PHP
When writing a function to save audio files with a user friendly filename , as well as a regex to remove any unwanted spaces and punctuation, I needed to replace any accented characters with their standard format.
e.g If I was saving a Beyoncé album I needed the ‘é’ in her name to be replaced with an ‘e’.
The following works perfectly:
iconv("utf-8","ascii//TRANSLIT",$filename);
Using Zend session with an HTML framset
Trying to incorporate a Zend session on a page being viewed as part of a frameset caused me a headache yesterday.
I couldn’t understand how everytime I refreshed the page to try and test the session it seemed to be reset. Var_dumping the session before and after the data was getting assigned showed that everything was getting stored as expected, but each time the page loaded, the session returned NULL again. Continue reading “Using Zend session with an HTML framset”
Nesting an onclick within an onclick
When trying to place an onclick function on a link in a table cell, which is part of a row which also has an onclick event, leads to both onclick functions being called.
After looking into how to go around this issue I used
1 2 3 |
e.stopPropagation(); |
This worked perfectly, stopping the parent onclick from firing, but when it came to testing in dreaded IE I found it wasn’t supported.
So I tried changing to:
1 2 3 |
e.cancelBubble = true |
This works just as well, not only in Firefox but IE too.