Tuesday, 26 July 2016

How to decode encoded html entities in javascript:

<?php

/**
* Decode a string with encoded characters like &amp;
* @param string encodedString - string to encode
* @return string
*/
function decodeEntities(encodedString) {
  var textArea = document.createElement('textarea');
  textArea.innerHTML = encodedString;
  return textArea.value;
}

console.log(decodeEntities("Keith & Hards"));

output: "Keith & Hards"




 

Wednesday, 20 July 2016

Passing JSON into php function as a parameter

Here is an example of hot to pass JSON into a php function as a parameter:

<?php

function print_details($json) {
 $args = json_decode($json);
 
 echo "My first name is {$args->first_name}<br />"; 
 echo "My last name is {$args->last_name}<br />"; 
 echo "My age is {$args->age}<br />";  
}


print_details('{
  "first_name": "keith",
  "last_name": "hards",
  "age": 37
}');
 

Wednesday, 6 July 2016

Linux:
How to find where your disk space has gone:

du -h --max-depth=4 | sort -hr


Though these days I tend to use ncdh which is perfect.