Daniel0
Staff Alumni-
Posts
11,885 -
Joined
-
Last visited
Everything posted by Daniel0
-
[SOLVED] getElementById() Not working in IE Why?? and NaN error
Daniel0 replied to garethhall's topic in Javascript Help
Have you checked that outputResult has the correct value? -
I haven't bothered doing any benchmark, but you could also do this: <?php $html = 'Images: <img src="test1.jpg" width="130" /> <img src="test2.jpg" width="50" /> <img width="256" src="test3.jpg" /> <img width="12" src="test4.jpg" /> <img src="nowidth.jpg" />'; $doc = new DOMDocument(); $doc->loadHTML($html); $images = array(); foreach ($doc->getElementsByTagName('img') as $img) { if ((int) $img->getAttribute('width') >= 200) { $images[] = $img->getAttribute('src'); } } var_dump($images); Edit: As expected, DOM is significantly slower, but still faster than CV's regex. <?php header('Content-type: text/plain'); $iterations = 10000; $tags = 50; $html = ''; for ($i = 0; $i < $tags; ++$i) { $html .= '<img src="test' . $i . '.jpg" width="' . mt_rand(50, 200) . '">'; } /** * Test DOM */ $start = microtime(true); for ($i = 0; $i < $iterations; ++$i) { $doc = new DOMDocument(); $doc->loadHTML($html); $images = array(); foreach ($doc->getElementsByTagName('img') as $img) { if ($img->getAttribute('width') >= 100) { $images[] = $img->getAttribute('src'); } } } echo 'Time (DOM): ' . (microtime(true) - $start); /** * Test regex */ $start = microtime(true); for ($i = 0; $i < $iterations; ++$i) { preg_match_all('~<img\b[^>]+width=[\'"][1-9][0-9]{2,}[\'"][^>]*>~i', $html, $matches); $matches[0] = preg_replace('~.+?src=[\'"](.+?)[\'"].+~is', '$1', $matches[0]); } echo PHP_EOL . 'Time (regex): ' . (microtime(true) - $start); /** * Test regex 2 */ $start = microtime(true); for ($i = 0; $i < $iterations; ++$i) { preg_match_all('~<img[^>]*(width\s?=\s?[\'"][1-9][0-9]{2,}(?:px)?[\'"])?[^>]*src\s?=\s?[\'"]([^\'"]*)[\'"][^>]*(?(1)|width\s?=\s?[\'"][1-9][0-9]{2,}(?:px)?[\'"])[^>]*>~i',$html,$matches); } echo PHP_EOL . 'Time (regex 2): ' . (microtime(true) - $start); Output on my computer: Time (DOM): 5.2172110080719 Time (regex): 1.754891872406 Time (regex 2): 9.2111718654633
-
Well, obviously your code is broken: daniel@daniel0:~$ cat | php <?php $sites = array('http://sdpk.info'); foreach ($sites as $site) { var_dump(get_headers($site)); } ^D array(15) { [0]=> string(30) "HTTP/1.1 301 Moved Permanently" [1]=> string(35) "Date: Sun, 09 Aug 2009 09:51:57 GMT" [2]=> string(14) "Server: Apache" [3]=> string(14) "Location: /ru/" [4]=> string(17) "Content-Length: 0" [5]=> string(23) "Content-Type: text/html" [6]=> string(15) "HTTP/1.1 200 OK" [7]=> string(35) "Date: Sun, 09 Aug 2009 09:51:57 GMT" [8]=> string(14) "Server: Apache" [9]=> string(62) "Set-Cookie: PHPSESSID=7b66914b01f789442dc1cfbbbda86785; path=/" [10]=> string(38) "Expires: Thu, 19 Nov 1981 08:52:00 GMT" [11]=> string(77) "Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0" [12]=> string(16) "Pragma: no-cache" [13]=> string(17) "Connection: close" [14]=> string(23) "Content-Type: text/html" }
-
For another time, the SSL development headers are in the package called libssl-dev.
-
Well, maybe you could tell me why the first command here returns a value and why the second gives the error you get? daniel@daniel0:~$ php -r "var_dump(get_headers('http://www.phpfreaks.com'));" array(10) { [0]=> string(15) "HTTP/1.1 200 OK" [1]=> string(35) "Date: Sun, 09 Aug 2009 09:29:50 GMT" [2]=> string(25) "Server: Apache/2.2.8 (EL)" [3]=> string(103) "Set-Cookie: phpfreaks_session=91gfcfoamietsvqnbc0ttuv783; expires=Mon, 09 Aug 2010 09:29:50 GMT; path=/" [4]=> string(38) "Expires: Thu, 19 Nov 1981 08:52:00 GMT" [5]=> string(77) "Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0" [6]=> string(16) "Pragma: no-cache" [7]=> string(32) "Vary: Accept-Encoding,User-Agent" [8]=> string(17) "Connection: close" [9]=> string(38) "Content-Type: text/html; charset=UTF-8" } daniel@daniel0:~$ php -r "var_dump(get_headers('http://www.lasjdlaksjd-does-not-exist.com-foo-bar'));" PHP Warning: get_headers(): php_network_getaddresses: getaddrinfo failed: Name or service not known in Command line code on line 1 PHP Warning: get_headers(http://www.lasjdlaksjd-does-not-exist.com-foo-bar): failed to open stream: php_network_getaddresses: getaddrinfo failed: Name or service not known in Command line code on line 1 bool(false)
-
when to delete old forum topics and their replies?
Daniel0 replied to dadamssg's topic in Application Design
Yeah we don't delete any content. Logs and old sessions get cleaned out, but not posts. It's not really an issue. Our database is only about 1 GB, but MySQL doesn't load all content into memory, so that's not really an issue. We are running a separate search daemon for the forums called Sphinx though. -
No, it's procedural. Functional programming is a much different paradigm.
-
Yeah, but even: INSERT INTO foo (bar) VALUES ('0x275061756c27'); Wouldn't work (from an attacker's point of view). If you've made sure that your string only contains alphanumeric characters and you delimit the string in quotes there is no way any SQL injection vulnerability would be possible.
-
Well, have you read the error message that is returned? What does it tell you?
-
Do note the distinction between ' (single quote) which delimits a string literal and the ´ (backtick) which delimits an identifier. You want INSERT INTO table (list of identifiers) VALUES (list of values);
-
eval('?>' . $string);
-
Well, you're doing like $returnValue = check_team_totaltally($player_1,$player_2,$player_3,$player_4,$player_5,$player_6,$player_7,$player_8,$player_9,$player_10,$player_11); so you could just do $totaltally = check_team_totaltally($player_1,$player_2,$player_3,$player_4,$player_5,$player_6,$player_7,$player_8,$player_9,$player_10,$player_11); instead. Also, I would refactor your function to take an array instead of 11 separate elements.
-
I actually don't think that Bing song is that bad. It's catchy, and that's what a jingle should be. It'll be stuck in your head and you'll keep thinking "Bing, Bing", you'll keep thinking about their product.
-
Actually, you grant us a "perpetual, irrevocable, world-wide, transferable, non-exclusive, royalty free license" (TOS). The distinction is that if you actually transfer the license to us you will no longer be able to use it yourself.
-
Heh... There is probably nothing we can do about poor communication skills. Just ignore the topic and move on to another one. That's their loss.
-
Haha... check out this shit: (from the TechCrunch comments)
-
Still better than the ...
-
1) See the sticky (you've been here for a long time, you ought to know how things work around here). Locked. 2) Why are adding various sorts of diacritical marks to your vowels? It looks stupid.
-
<?php header('Content-type: text/html; charset=utf-8'); function unicode2utf8($c) { $output=""; if($c < 0x80) { return chr($c); } else if($c < 0x800) { return chr( 0xc0 | ($c >> 6) ).chr( 0x80 | ($c & 0x3f) ); } else if($c < 0x10000) { return chr( 0xe0 | ($c >> 12) ).chr( 0x80 | (($c >> 6) & 0x3f) ).chr( 0x80 | ($c & 0x3f) ); } else if($c < 0x200000) { return chr(0xf0 | ($c >> 18)).chr(0x80 | (($c >> 12) & 0x3f)).chr(0x80 | (($c >> 6) & 0x3f)).chr(0x80 | ($c & 0x3f)); } return false; } $string = '%u0E19%u0E32'; $string = preg_replace('#%u([0-9a-f]+)#ie', 'unicode2utf8(0x$1)', $string); echo $string; The unicode2utf8() function came from: http://php.net/manual/en/function.unicode-encode.php#79829
-
Copyright law would prohibit it.
-
Lol what happened to the equation in the quote?
-
Failblog fail... [tex]0.002+e^{i\pi}+\sum_{n=1}^\infty \frac{1}{2^n} = 0.002 - 1 + 1 = 0.002[/tex] Edit: Quoted the wrong one. Daniel fail.
-
"The dialed number is imaginary. Please rotate your phone and try again."
-
Code should be self-documenting. You shouldn't have to comment on what the code does, but rather why it does it (unless it's obvious).