Monday, September 30, 2013

Json_decode Error: Cannot use object of type stdClass as array

Oops.. I found this Fatal error: Cannot use object of type stdClass as array in /home/username/html/index.php on line 13 when using json_decode() function. How to fix this?

Simply add true parameter. This will solve the problem:

$row = json_decode( $json_data, true );

// now you can use $row as array

echo $row['name'];

Thursday, September 26, 2013

Perfect PHP Email Regex

This is a perfect regular expression for validating email address from text inputs form. It matches common email address format. Here is the email regex I often use on PHP or Javascipt.

/([a-z0-9_]+|[a-z0-9_]+\.[a-z0-9_]+)@(([a-z0-9]|[a-z0-9]+\.[a-z0-9]+)+\.([a-z]{2,4}))/i

The regular expression above matches email addresses like:
  • myemail@example.com
  • my_email@example.com
  • my.email@example.com
But not for:
  • myemail.@example.com
  • .myemail@example.com

Thursday, September 19, 2013

How to display QR Code dynamically on blogspot using Google Chart Tools

Hi, did you see QR Code on my widget? You should be able to see there, on the right sidebar. Yes, that's dynamic qr code I created using Google Chart Tools and jQuery. It creates QR Code contains current URL of the page. If you like too, I'll show you how I did this little trick. Now you can simply do this on your blog, on any blog. Here's how:

Example jQuery slideToggle

The simple example playing with jquery slideToggle().

<script>
$(function(){
   $('.toggle').click(function(){
       var el = $(this).attr('rel');
       $(el).slideToggle();
   }); 
});
</script>

<button class="stoggle" rel="#hideMe">Click me</button>
<br />
<div id="hideMe" style="background: #ffffd0; display: none; height: 100px; text-align: center; width: 200px;">
I'm the hidden element
</div>

Demo: or toggle the element above:

By adding "rel" attribute, we can toggle specific elements.

Remove blogthis button on blogspot

Using blogspot to blog everything is fun, easy and absolutely free. But how if you don't want someone stole your valuable contents simply by pressing Blogthis button on your blog posts?

Event this feature includes backlink to your post, people can remove it easily from rich textarea. So I decided to remove this button by editing HTML template. Checkout this: