wtf!?
1
Name:
Anonymous
2011-03-06 0:51
er... why doesnt sort() do what I am expecting here?
<?
Header("content-type: application/x-javascript");
$pathstring=pathinfo($_SERVER['PHP_SELF']);
$locationstring="http://" . $_SERVER['HTTP_HOST'].$pathstring['dirname'] . "/";
function returnimages($dirname=".") {
$pattern="(\.jpg$)|(\.png$)|(\.jpeg$)|(\.gif$)";
$files = array();
$curimage=0;
if($handle = opendir($dirname)) {
while(false !== ($file = readdir($handle))){
if(eregi($pattern, $file)){
echo 'picsarray[' . $curimage .']="' . $file . '";';
$curimage++;
}
}
closedir($handle);
}
$files = sort($files);
return($files);
}
echo 'var locationstring="' . $locationstring . '";';
echo 'var picsarray=new Array();';
returnimages()
?>
2
Name:
Anonymous
2011-03-06 0:56
PHP: Hates Programmers
3
Name:
Anonymous
2011-03-06 1:16
bro
4
Name:
PHP FAGGOT
2011-03-06 1:46
>>1
bool sort ( array &$array [, int $sort_flags = SORT_REGULAR ] )
Because it sorts the array in-place. Try reading the documentation.
5
Name:
Anonymous
2011-03-06 6:55
ok, how about this then:
why does the first codeblock work fine
and the second codeblock just renders a blank page in firefox 3.6.14 ?
<?php
$images = array();
$pattern="/(\.jpg$)|(\.png$)|(\.jpeg$)|(\.gif$)/";
if($handle = opendir(".")) {
while(false !== ($file = readdir($handle))) {
if(preg_match($pattern, $file)) {
array_push($images, $file);
}
}
closedir($handle);
}
if (!function_exists('json_encode'))
{
function json_encode($a=false)
{
if (is_null($a)) return 'null';
if ($a === false) return 'false';
if ($a === true) return 'true';
if (is_scalar($a))
{
if (is_float($a))
{
// Always use "." for floats.
return floatval(str_replace(",", ".", strval($a)));
}
if (is_string($a))
{
static $jsonReplaces = array(array("\\", "/", "\n", "\t", "\r", "\b", "\f", '"'), array('\\\\', '\\/', '\\n', '\\t', '\\r', '\\b', '\\f', '\"'));
return '"' . str_replace($jsonReplaces[0], $jsonReplaces[1], $a) . '"';
}
else
return $a;
}
$isList = true;
for ($i = 0, reset($a); $i < count($a); $i++, next($a))
{
if (key($a) !== $i)
{
$isList = false;
break;
}
}
$result = array();
if ($isList)
{
foreach ($a as $v) $result[] = json_encode($v);
return '[' . join(',', $result) . ']';
}
else
{
foreach ($a as $k => $v) $result[] = json_encode($k).':'.json_encode($v);
return '{' . join(',', $result) . '}';
}
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html xmlns="http://www.w3.org/1999/xhtml ">
<head>
<meta http-equiv="Content-Type" content="application/xml; charset=UTF-8" />
<title>/photos</title>
<style>
*
{
margin: 0px;
padding: 0px;
font-family: "Georgia", serif;
}
html, body
{
width: 100%;
height: 100%;
}
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js ">
</script>
<script>
$(function() {
var images = <?php print(json_encode($images)); ?>;
images.sort();
var images_lol_at_once = 10;
var image = 0;
var func = function() {
console.log(image);
if($("body").scrollTop() > $("#images").height() - $(window).height() - 100) {
var end = image + images_lol_at_once;
for( ; image < end; image++) {
if(image >= images.length) {
clearInterval(interval);
return;
}
$("#images").append('<alt="'+images[image]+'"/ img src="'+images[image]+'"/>');
}
}
};
func();
var interval = setInterval(func, 1000);
});
</script>
</head>
<body>
<div id="images"></div>
</body>
</html>
<?php
$images = array();
$pattern="/(\.jpg$)|(\.png$)|(\.jpeg$)|(\.gif$)/";
if($handle = opendir(".")) {
while(false !== ($file = readdir($handle))) {
if(preg_match($pattern, $file)) {
array_push($images, $file);
}
}
closedir($handle);
}
if (!function_exists('json_encode'))
{
function json_encode($a=false)
{
if (is_null($a)) return 'null';
if ($a === false) return 'false';
if ($a === true) return 'true';
if (is_scalar($a))
{
if (is_float($a))
{
// Always use "." for floats.
return floatval(str_replace(",", ".", strval($a)));
}
if (is_string($a))
{
static $jsonReplaces = array(array("\\", "/", "\n", "\t", "\r", "\b", "\f", '"'), array('\\\\', '\\/', '\\n', '\\t', '\\r', '\\b', '\\f', '\"'));
return '"' . str_replace($jsonReplaces[0], $jsonReplaces[1], $a) . '"';
}
else
return $a;
}
$isList = true;
for ($i = 0, reset($a); $i < count($a); $i++, next($a))
{
if (key($a) !== $i)
{
$isList = false;
break;
}
}
$result = array();
if ($isList)
{
foreach ($a as $v) $result[] = json_encode($v);
return '[' . join(',', $result) . ']';
}
else
{
foreach ($a as $k => $v) $result[] = json_encode($k).':'.json_encode($v);
return '{' . join(',', $result) . '}';
}
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html xmlns="http://www.w3.org/1999/xhtml ">
<head>
<meta http-equiv="Content-Type" content="application/xml; charset=UTF-8" />
<title>/photos</title>
<style>
*
{
margin: 0px;
padding: 0px;
font-family: "Georgia", serif;
}
html, body
{
width: 100%;
height: 100%;
}
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js ">
</script>
<script>
$(function() {
var images = <?php print(json_encode($images)); ?>;
images.sort();
for(var i in images) {
$("#images").append('<img src="'+images[i]+'"/>');
}
});
</script>
</head>
<body>
<div id="images"></div>
</body>
</html>
6
Name:
Anonymous
2011-03-06 6:57
fuck off with your PHP shit
7
Name:
Anonymous
2011-03-06 6:58
whoops, i mean the first does NOT work and the second does... doh
8
Name:
Anonymous
2011-03-06 23:04
>>5
why does the first codeblock work fine
> and the second codeblock just renders a blank page in firefox 3.6.14 ?
For fuck's sake. Add some print statements and find out. Or even better, use an actual debugger and trace through it.
9
Name:
Anonymous
2013-08-31 13:25
Do they still have the fatigue system for each class though? I remember just botting fishing and the crafting skills overnight because of that bullshit. I'll probably give it a try if I don't have enough fun with gw2 this weekend though.
10
Name:
Anonymous
2013-08-31 14:10
I wonder what color panties is she wearing
11
Name:
Anonymous
2013-08-31 14:55
As expected of Kuro-chan, the strongest Saki.
12
Name:
Anonymous
2013-08-31 15:41
Not a single mention of "idiot" in the post, and you get that out of it.