-
Posts
1,943 -
Joined
-
Last visited
Never
About discomatt
- Birthday 10/19/1986
Contact Methods
-
AIM
mcmuffinator
-
MSN
mmatt300@hotmail.com
Profile Information
-
Gender
Male
-
Location
Surrey, British Columbia
discomatt's Achievements
Member (2/5)
0
Reputation
-
Jibberish has it. You must reset the internal pointer after $row = mysql_fetch_array($result); Remove it or try mysql_data_seek()
-
May I have 5.2^114 guesses?
-
Check the forums here http://www.geonames.org/ They know their stuff
-
I've always liked this method: Generate random salt ( usually of the same length as the hash ) Chop the password and salt into 2 chunks. Mix chunks and hash. Split hash into 2 parts, mix with salt. You now have the salt stored in plain text, but it's theoretically impossible to extract it from the hash without knowing the chunk sizes and algorithm used. It's a little paranoid, but it's actually a very light script ( php is very quick and string manip ) requiring only 1 hash to check a password. Salting is VERY VERY important. I would argue a random salt is equally important. You're protecting your viewers passwords they might use elsewhere. Rainbow tables are becoming huge and easy to access.
-
Comparing 2 Arrays - Is there a better way to do this?
discomatt replied to discomatt's topic in PHP Coding Help
That's another neat concept, but that one is a hog, running about 10x slower than our previous functions using realistic depth, and nearly 15x slower than mine on unrealistic depths. I think I'm going to stick with either your or my original function, pending a little more speed testing. Thanks again for the time and thought, and helping me look outside the box -
[SOLVED] When using strtotime what type do you use in MYSQL?
discomatt replied to limitphp's topic in PHP Coding Help
You're better off using MySQL's timestamp type column... -
I think the issue is the end user typing in double stars. Your best bet is to match \*++ in the regex that does the conversion.
-
Comparing 2 Arrays - Is there a better way to do this?
discomatt replied to discomatt's topic in PHP Coding Help
That works great! Neat way of doing it. Speed wise, the functions are near equal in real-life situations... I did trials using random data with an average depth ~5 and my function edged out yours by a negligible time. When doing unrealistic trials ( average depth ~100 ) your function ran about 3x faster than mine. Thanks for the help sasa! -
Comparing 2 Arrays - Is there a better way to do this?
discomatt replied to discomatt's topic in PHP Coding Help
Here's a working example of what I'm doing on a broader scope <pre><?php /* 1 67 20 107 43 116 77 153 125 161 */ $data = <<<DATA {loop} Some data {loop} Nested data {loop} More nests! {/loop} {loop} Another deep nest {/loop} {/loop} {loop} Not quite so deep {/loop} {/loop} {loop} More data {loop} Foobar {/loop} {loop} Warmer {loop} Waaaarmer {loop} Too hot! {/loop} {/loop} {/loop} {loop} More depth {loop} this is getting stupid {/loop} {/loop} {/loop} DATA; $pairs = getPairs($data, '{loop}', '{/loop}'); foreach( $pairs as $pair ) echo substr( $data, $pair[0], $pair[1]-$pair[0] ) . "\n\n\n--------\n\n\n"; function getPairs( $data, $openTag, $closeTag ) { // Grab opening and closing offsets $opening = getOffsets( $data, $openTag ); $closing = getOffsets( $data, $closeTag, FALSE ); // Verify proper formatting if( ($size = count($opening)) !== count($closing) ) die( "Invalid syntax detected" ); // Placeholder $offsets = array(); // Separate nests for( $i = 1; $i < $size; $i++ ) { // Set initial nest key static $last = 0; // Check to see if a new nest has begun if( isset($opening[$i+1]) === FALSE || $opening[$i+1] > $closing[$i] ) { // Send nest to parser and gather results $offsets = array_merge( $offsets, parseNest(array_slice($opening,$last,$i-$last+1), array_slice($closing,$last,$i-$last+1)) ); // Update nest key to the start of the next nest $last = $i+1; } } return $offsets; } function getOffsets( $data, $tag, $open = TRUE ) { // Placeholder $return = array(); // Start at beginning of string $offset = 0; // Loop through string grabbing offsets while( ($c = strpos($data, $tag, $offset)) !== FALSE ) { // Update search offset $offset = strpos( $data, $tag, $c ) + 1; // Remove tag offset and add to placeholder $return[] = $offset - 1 + ( $open == TRUE ? strlen($tag) : -1 ); } return $return; } function parseNest( $opening, $closing ) { // Placeholder $pairs = array(); // Loop through $opening backwards foreach( array_reverse($opening) as $oVal ) { /***** THIS IS THE CHUNK I THINK CAN BE IMPROVED ON *****/ // Loop through $closing until we find a value less than the current $opening foreach( $closing as $cKey => $cVal ) // Check to see if the current opening is less than the current closing if( $oVal < $cVal ) { // If so, add it to the pairs $pairs[] = array( $oVal, $cVal ); // Unset used value of b - prevents duplication and should speed things up unset( $closing[$cKey] ); // Break out of the loop break; } /***** END OF CHUNK *****/ } // Return them in ascending order return array_reverse( $pairs ); } ?></pre> -
Comparing 2 Arrays - Is there a better way to do this?
discomatt replied to discomatt's topic in PHP Coding Help
Zegan, I'm not exactly sure what you're doing... but your solution seems, well, overly complex? Also, you should never use for ($i=0; $i <count($a); $i++) Unless you expect count($a) to change. You should instead use for ($i=0, $c=count($a); $i < $c; ++$i) -
Comparing 2 Arrays - Is there a better way to do this?
discomatt replied to discomatt's topic in PHP Coding Help
Okay, let me expand on this. It's a function to match up nested pairs of strings. Array $a would be the offsets for opening tags, while array $b would be the offsets of closing tags. bobbinsbro : The arrays will/should always be in ascending order... and if it wasn't, I can always use sort() before looping. sasa: Yes, they should both be in ascending order at all times. corbin: It's part of the algorithm. In order to find the correct matching pairs, it takes the least amount of work to start from the opening end ( deepest element ) and work your way up/out. Just to clear things up, here's what I'm doing, in a wider scope. This is a crude example... the actual code I'm using is nested in a class with a ton of erroneous garbage so I shortened it up [edit] oops, gotta clean a few things up before i can provide an example [/edit] Thanks for your replies thus far -
Comparing 2 Arrays - Is there a better way to do this?
discomatt replied to discomatt's topic in PHP Coding Help
Shameless BUMP -
Well, if you want to follow PHP's function naming spec. '/[a-z_\x7f-\xff][a-z0-9_\x7f-\xff]++\([^)]++\)/i' This is assuming you won't use literal strings with closing brackets in your function... for example bleh('Stuff with a ) closing bracket') If you want something like that, the expression becomes quite a bit more complex
-
First I'll try to explain the problem. I have 2 arrays of identical size, similar to the example below $a = array( 2, 29, 54, 77 ); $b = array( 66, 72, 102, 107 ); I want to go through each value of $a in reverse, and find the lowest value of $b that is greater than the current value of $a. To add to this mess, I don't want to reuse any values of $b when pairing them with values from $a Here's what I've got so far <pre><?php $a = array( 2, 29, 54, 77 ); $b = array( 66, 72, 102, 107 ); // Placeholder for found pairs $pairs = array(); // Loop through $a backwards foreach( array_reverse($a) as $aVal ) { /***** THIS IS THE CHUNK I THINK CAN BE IMPROVED ON *****/ // Loop through $b until we find a value less than the current $a foreach( $b as $bKey => $bVal ) // Check to see if the current value of b is less than the current value of a if( $aVal < $bVal ) { // If so, add it to the pairs $pairs[] = array( $aVal, $bVal ); // Unset used value of b - prevents duplication and should speed things up unset( $b[$bKey] ); // Break out of the loop break; } /***** END OF CHUNK *****/ } print_r( $pairs ); ?></pre> The output should look like this Array ( [0] => Array ( [0] => 77 [1] => 102 ) [1] => Array ( [0] => 54 [1] => 66 ) [2] => Array ( [0] => 29 [1] => 72 ) [3] => Array ( [0] => 2 [1] => 107 ) ) Any help is greatly appreciated. I'm hoping there's some cool array trick I just don't know about. Thanks for lookin'
-
I believe underscore is already matched in the \w shorthand so you could make it even shorter