Perchè non provi a tradurre quanto scritto in codice PHP, è piuttosto elementare.