June 29, 2017

$list = $tab_one['special_days']; // import list
$list = explode(PHP_EOL, $list); // split after new line

// At this point I will assume that you have a line like
// '06/28 > 5:00-23:00' in each list item 

$finalArray = []; // To store the array

foreach($list as $item) {
    $item = explode('>', $item); // split after ">"
    $finalArray[$item[0]] = explode(',', $item[1]);
}

var_dump($finalArray);

Note that the items exploded from $item[1] have not been trimmed so might have whitespaces.

Your problem is that you have quoted the column name. Use

$insert_row = "INSERT INTO comments (comment) VALUES 
('".$contentToSave."')";
June 28, 2017

Auto version your JavaScript or Stylesheet files using .htaccess

Usually, developers can maintain the cache they maintain themselves at the backend but cannot control the cache held by the browser as freely as they want unless there is proper version control. Here is a quick drop in solution in `.htaccess` file until you have proper versioning.

Most of the applications have one or many layers of cache for their system. The cache that application developer can maintain is at the backend (the server) level. However, you cannot control the cache held by the browser as freely as you want unless you version the files as well.

Versioning the files is definitely the best way to solve this problem because it is a very efficient solution which guarantees that browser will fetch the new resource when you want it to. But there are cases where this is not an easy step to be taken, for example, in a legacy app which resources are included in line the page.

So, is there a quick way to fix the problem until you go to proper versioning?

Yes! there is.

Using .htaccess we can auto version the files and force the browser to fetch files down to every second if we need to.

Here is how:

We can use server variables such as TIME_YEAR, TIME_MONTH to create an automatic version of your resource. These are variables that the web server provide to be used where suitable. And now, let’s see how to do this.

RewriteCond %{QUERY_STRING} !(v=(.<em>))
Rewriterule ^(js|scripts|css|styles)(.</em>)$ /$1$2?v=%{TIME_YEAR}%{TIME_MON}%{TIME_DAY}%{TIME_HOUR} [r=302,nc]`

Open your .htaccess files and paste those two lines in. What these are doing is:

  • If a request comes to the server that starts with js, scripts, css or styles then rewrite the request by appending an auto-created version at the end.
  • IF a request comes with the version already in the request then don’t do anything because we don’t want it to keep rewriting the request.

Simple as that. So for example: if the request comes to https://abc.com/js/main.js it gets served as https://abc.com/js/main.js?v=2017062811. Same goes for any request coming to other paths as well. This example ensures that browser will fetch the resource again every hour. But if you add variables like TIME_MINUTE or TIME_SECOND or TIME browser will keep fetching the content more frequently.

To see what other server variables can be used visit https://httpd.apache.org/docs/trunk/expr.html#vars

June 13, 2017

enum is a reserved keyword so you should not use such reserved keywords.

Find a working example of your code below:

var t_enum = {
    aitem: {
        Desc: 'A description',
        Value: 0,
        Group: 'A'
    },
    bitem: {
        Desc: 'b description',
        Value: 1,
        Group: 'B'
    },
    bitem: {
        Desc: 'c description',
        Value: 2,
        Group: 'C'
    }
}
var neededGroup = 'A';
var neededValues = [];

Object.keys(t_enum).forEach(function (x) {
    var item = t_enum[x];
    if (item.Group == neededGroup){
        neededValues.push(item.Value);
        return;
    }
})
console.log(neededValues);

Demo

Its an alternate approach from what Toddo is suggesting.

June 6, 2017

You cannot change the content the label itself, but you can control the content of the pseudo element after and before. You can add the logic of square/circle with something that can represent check and uncheck.

input[type='checkbox'] {
  width: 0;
  height: 0;
}

input[type='checkbox']:checked + label:after {
  content: "checked";
}

Demo

To answer your question in the comment

How they make funky circle buttons and put a checkbox inside it when one clicks?

You can use CSS animations. The label will already have the check symbol in it but won’t have shown in the unchecked state of the input box. And when the element is checked, it will change the opacity to 1, showing the checkbox in an animated way.

input[type='checkbox'] {
  width: 0;
  height: 0;
}

input[type='checkbox'] + label:after {
  content: "checked";
  opacity: 0;
  -webkit-transition: all 0.50s; 
  -moz-transition: all 0.50s;
  -o-transition: all 0.50s;
  transition: all 0.50s;
}

input[type='checkbox']:checked + label:after {
  opacity: 1;
}

Demo

...

Please fill the form - I will response as fast as I can!