Archive for the ‘PHP’ Category
Few very useful PHP functions
In this post I would like to present a few PHP functions which I created for projects I worked on and which I found very useful many times.
The functions are not super-advanced, but really handy. You can use them freely as they all are licensed under MIT.
I think there is a big chance you will find them useful too. If you do- please leave a comment, thanks!
PHP Error: unserialize() [function.unserialize]: Error at offset 118 of 512
Lately I got this error in my script while trying to decode serialized UTF-8 string:
unserialize() [function.unserialize]: Error at offset 118 of 512
Here’s a simple solution I found.
Typekit- another way to use nonstandard fonts on a website
I already described cufon method so now I want to focus on another method- Typekit.
Typekit.com is a website which lets you use over 500 nonstandard, nonwebsafe fonts. If you have a website with less then 25000 pageviews per month then you can use they services for free.
PHP: Nice URL shortener to use from PHP
In this post I would like to present you a nice URL shortening service that you may use from PHP in a very simple way (perhaps simplest possible!).
Let’s say you want to shorten url like this:
http://www.my-website-is-here.com/index.php?subpage
To do this you need this simple code:
$url = ‘http://www.my-website-is-here.com/index.php?subpage’;
$new_url = file_get_contents(‘http://is.gd/api.php?longurl=’ . urlencode($url));
Now you can echo $new_url to see [...]
PHP: Smarty: {foreach} doesn’t render my array
On one of the websites I work I couldn’t render an array in a smarty template. My code looked like this:
{foreach from=$myarray key=mykey item=items}
<h2>{$mykey}</h2>
{foreach from=$items item=it}
{$it.value}
{/foreach}
{/foreach}
I used print_r in my controller to show content of $myarray and it was just fine. After a while I found the error: Zend Framework did not allow me
to work [...]
Fatal error: Call to undefined function exif_read_data() in www\index.php on line 10
I recently got this error while trying to read EXIF data from jpegs.
So I enabled exif extension in php.ini but when I restarted Apache
I was informed that “php_exif.dll cannot not be found”.
I checked “ext” directory of my PHP installation and the file was there.
After doing some research I discovered that in order to use EXIF [...]
PHP: How to safely include file with possible parse errors?
Recently I had written a class and it had to save bits of information somewhere. I wanted to make the script installable just by placing it on a server so I didn’t want to use any database. Instead I figured out I should save the data in a simple file. I could use serialize and file_put_contents which is very easy to write, but modifying such files manually in a text editor is a nightmare. So I decided to save the contents in a PHP file.
Unfortunately if there is an error in such file you will get parse error when including it.
PHP: Date format for sitemap.xml
Sitemap.xml files require special date format. Example valid date is: 2010-10-06T11:56:00+01:00
Magento Error: Method Varien_Object::__tostring() cannot take arguments
If you encountered a bug in Magento that says:
Method Varien_Object::__tostring() cannot take arguments
and you have PHP 5.3 or newer then you have 2 options:
1) downgrade to PHP 2.9
2) fix the bugs
PHP: Convert Youtube links in text into embedded videos
Here’s a nice function I wrote which can convert any youtube links found in a string into embedded videos.