Archive: php

 

Reading the generally very clear and concise Yii documentation you can quickly get started with the framework. However one issue that I struggled to be clear on is setting up the database driven authorisation system. I recommend reading this blog post which finally helped me to understand wth I was supposed to do. The official [...]



 

If you want to serve up text files for download (perhaps product feeds etc) then you might like this little snippet. Not only will it force the file to be downloaded but it allows you to specify a custom filename that it should be saved as. PLAIN TEXT PHP: if(isset($_GET['download_file'])){     header("Content-type: application/octet-stream");   [...]



 

On occasion, google and other tools will tell you there's errors with your sitemap.xml file and not give you the information of what exactly is wrong, so we wrote this little tool to crawl the sitemap and check for 301 redirections and 404 errors. It is a noddy file and should have much more error [...]



 

Need to take a string of text and shorten it down but make sure you split on a word break? This little snippet might be exactly what you are looking for. PLAIN TEXT PHP: $text=substr($text, 0, strpos($text, ' ', 50)); effectively you are saying give me the position of the first space after character 50 [...]



 

Often you will come across a situation where you have to do a mass of redirects, often when moving platform e.g. from osCommerce to Magento. So you might create a whole load of .htaccess rules which you want to verify, either before or after implementing them. Rules like : RewriteRule ^top-level-category/old-category/product-name-p-3944.html$ new-product-name.html I wrote this [...]



 

If you would like your users to be able to spell check their text before they send it and need something more than the browser based spell checking then this could be of interest. Recently came across this and it looks very impressive: http://www.phpspellcheck.com/ There is a commercial licence for $89 which is a reasonable [...]



 

The php simpleXML object is my preferred way of working with XML, but it has some unusual quirks that can drive you up the wall. One of these is that, by default, it will not read CDATA within an XML file, and will just leave the node blank. If you need to access this data [...]



 

We told you about HipHop a while back and we were pretty excited about it. Now Facebook have decided to develop a virtual machine to allow dynamic translation and faster results than their previous interpreter based approach. This is paving the way for further performance improvements and ease of development. You can read the full [...]



 

If you are struggling trying to get PHPMailer working with Google Apps then perhaps this is the solution for you. I went to the PHPMailer site and found my way to a SourceForge download. After a lot of debugging and wrestling with this I just could not get it to work. In the end I [...]



 

Perhaps not as well known as it should be, PHP's glob() function is really quite powerful and exceptionally handy. Need to get a list of files in a directory - try this: PLAIN TEXT PHP: $tools = glob('includes/tools/*'); var_dump($tools); Want to delete all files matching a specific pattern, try this: PLAIN TEXT PHP: array_map('unlink', glob('export_feeds/my_feed_*')); [...]