daniele's blog

php goodies: filter

Filter is in php by default from 5.2.0 and is a usefull library for web developer, so it is the time to make use of it.

It was created for validation and sanitization of foreign input, that is GET, POST, COOKIE, or anything that you can't trust on. With php filter one can tests if a variable is present in the current request: 

if(filter_has_var(INPUT_POST,'login')) {
//manage login
}

Using this function a check state of a checkbox in a form could be tested as well:

Simplepie and CodeIgniter

yes, found: http://www.haughin.com/code/simplepie/
and tried with php 5.3 installation ... simply do not work

I recalled there was a problem in simplepie for assign new by reference, just downloaded newer code from http://simplepie.org/ ... still same problem.

So

{syntaxhighlighter brush:bash}
sed 's/=&\ new/=\ new/' simplepie.inc > Simplepie.php
{/syntaxhighlighter}

shuffle db table order

simple code to shuffle a table ... with php shuffle:

$result = $mysql->query("SELECT id FROM $table ORDER BY id");
$rows = $result->num_rows;
$order = shuffle(range(1,$rows));
while($row=$result->fetch_row()) {
  $num=array_shift($order);
  $mysql->query("UPDATE $table SET rand_sort=$num WHERE id=".$row[0]);
}

added:
with MySQL RAND():

Ajax frontend for my backoffice in jQuery and PHP

This is my way to organize php for a simple jQuery frontend ajax based:

1.in a administration page include the php that generate html for each box
2.for each box setup behavior in Javascript
3.let each php manage POST request (for change/update) and GET request for show content


So in admin.php we could have something like that

innerHTML problem with internet explorer (supposed)

I lost some time to debug this

$("#link").click(function(){
   $("#target").load('url/to/load');
});

The problem is on Internet Explorer (all version) that refuse to load data in #target, using $.get and innerHTML(data) do not help. The problem is with no well formed html! Internet Explorer refuse to load in dom a malformed html.
Thus