Transcription javascript calculations for PHP

4

How can I transcribe this code into javascript for PHP?

var temp = "<div class='brick' style='width:{width}px;'><img src='i/photo/{index}.jpg' width='100%'></div>";
var w = 1, h = 1, html = '', limitItem = 49;

for (var i = 0; i < limitItem; ++i) {
    w = 1 + 3 * Math.random() << 0;
    html += temp.replace(/\{width\}/g, w*150).replace("{index}", i + 1);
}

I'm sorry if I'm asking a simple question, but I'm a layman in PHP.

    
asked by anonymous 15.12.2014 / 03:49

1 answer

6

There is something similar:

<?php
    $html = '';
    $limitItem = 49;
    for ($i = 0; $i < $limitItem; ++$i ) {
        $w = rand( 1, 4 ); // Confira se é de 1 a 4 mesmo que deseja
        $width = $w * 150;
        $index = $i + 1;
        $html += '<div class="brick" style="width:' . $width . 'px">';
        $html += '<img src="i/photo/' . $index . '.jpg" width="100%"></div>';
    }
    //se quiser conferir o resultado:
    echo $html;
?>
    
15.12.2014 / 03:57