Crop text without splitting words
- Details
- Published on Wednesday, 14 December 2011 10:07
An example of some code that crops text without stopping part way through a word.
$description = $crop_desc ?
implode(" ", array_slice (explode(" ", $details->Description),0, $crop_desc)).'...'.$morelink
: $details->Description;
Joomla version numbers
- Details
- Published on Tuesday, 06 December 2011 13:32
I had to consult the Wikipedia for more information on the Joomla versions recently to clear up a few things.
I've obviously missed a few things as I was expecting 1.8 to be the next release but I started to see some talk of version 2.5.
There were some proposals and a vote but both options still don't seem to fit in with my view on version numbering. I always thought the first number should be a major release, the second number a minor release and the third number a bug fix. It seems daft that you should end up having a vote to try and make sense of the confusing numbers as it should really have been quite simple.
Find files in Unix that were modified n days ago
- Details
- Published on Thursday, 01 December 2011 23:00
To find all PHP files that were modified on a linux server in the last 7 days you can do the following
find . -mtime -7 -name "*.php" -print
Wrap an image tag with a link in PHP
- Details
- Published on Thursday, 01 December 2011 22:46
I found the following bit of code useful for automatically creating Joomla lightbox images from image tags.
echo preg_replace('`.+?)src="/([^"]+)"(?.+?)>`','<a class="modal" href="/$2">', $text);
In this example I've used the Joomla modal behavior but you can easily alter this for Jquery using rel or something similar.
Virtuemart queries
- Details
- Published on Wednesday, 23 November 2011 08:16
Really Virtuemart? Putting url's inside SQL statements isn't such a great idea. Its possible that its faster but I wouldn't have thought so and considering the queries Virtuemart does anyway it won't make any difference.
Part of the work I've been doing is creating an optimised version of Virtuemart and its little things like this that I like to tidy up.
Javascript to close popup window and load parent
- Details
- Published on Thursday, 03 November 2011 17:12
Whilst looking at authentication applications I found this piece of code handy
window.opener.location.href = window.opener.location.href;
if (window.opener.progressWindow)
window.opener.progressWindow.close()
window.close();
Regex to remove non ascii characters
- Details
- Published on Wednesday, 02 November 2011 20:49
Remove non ascii characters from a string with the following rgex
$new = preg_replace("/[^\x9\xA\xD\x20-\x7F]/", "", $old);
Regex to convert urls to links
- Details
- Published on Wednesday, 02 November 2011 15:42
A handy PHP regex to replace urls in a section of text to links.
$text = preg_replace('#(?])((http|ftp)s?://[^<>\s]+)#i', '\\0', $text );
Joomla sh404sef component
- Details
- Published on Monday, 17 October 2011 21:41
Pro PHP Refactoring
- Details
- Published on Sunday, 16 October 2011 20:17
I borrowed a copy of Pro PHP Refactoring recently and while it started out quite promising its not held my attention. I really liked the ideas it suggests and value the process of refactoring over "starting again" but I just found that a lot of the content was very "samey".
Its reasonably well laid out and provides good examples but I found myself struggling to concentrate on a lot of it and reckon that it could have been done a lot more succinctly. Many of the example ideas and processes could be combined in to one process.
Its another Apress title which you can find out more about on the Apress site here.