Jump to content

lococobra

Members
  • Posts

    81
  • Joined

  • Last visited

    Never

Contact Methods

  • AIM
    lococobra105
  • MSN
    trappar@lococobra.com
  • Yahoo
    trappar

Profile Information

  • Gender
    Not Telling

lococobra's Achievements

Member

Member (2/5)

0

Reputation

  1. Ah, stupid me... Wasn't paying attention to the month.. On the php.net comments someone said that first day would get the first day of the month. Anyone have an alternative method of getting that?
  2. Current time when testing was: 1291064453 I run the following: echo date('m/d/y', strtotime('first day', 1291064453)); Expecting: 11/1/10 What I actually get: 11/30/10 Can anyone explain this?
  3. Solved it myself. Here's a really rough version before I started applying the concept to the code I'm working on. I also made a version that just uses a single function, which accesses global variables to save results.. but that seemed even dirtier. I don't know if this will be useful for anyone, but it's a good jumping off point for more practical applications. I'm using this to find combinations of various pieces of text which, when put together, will yield a target word count. The unfortunate thing is that the results of this function are modeled by a factorial equation. So in other words, numbers over 10 or so will take a very long time and tons of memory to process. To speed things up a bit, you can limit the number of possibilities given in any combination by capping the recursion level (see the commented out line) class getPermutations { private $nums, $save; public function get($count){ $this->recurse($count, 0); return $this->save; } private function recurse($count, $level){ if($level == 0) $count++; //if($level >= 5) return; for($i=1;$i<$count;$i++){ $this->nums[$level] = $i; $this->save[] = implode(',', array_slice($this->nums, 0, $level+1)); $this->recurse($i, $level+1); } } }
  4. I'm not entirely sure I understand what you're asking. As far as I can tell.. 1) the possible values will always be 1-X, so all that's needed is the stop value. In this case, 4 2) the number of places? I think you mean how many of the possible values will be used for each possible output? If that's what you mean then all possible lengths. In this case, the outputs can be of length 1 - 4
  5. I'm trying to find all the possibilities for every combination of 1-X The code I've written currently works fine, but to make it work in more than one case, I need to make it recursive. Try as I might, I can't seem to wrap my head around this. Here's the non-recursive code: for($i=1;$i<=4;$i++){ echo $i.'<br>'; for($j=1;$j<$i;$j++){ echo $i.','.$j.'<br>'; for($k=1;$k<$j;$k++){ echo $i.','.$j.','.$k.'<br>'; for($l=1;$l<$k;$l++){ echo $i.','.$j.','.$k.','.$l.'<br>'; } } } } As you can see, it gives every possible combination of the numbers 1-4 without having any duplicate numbers. The number of loops must be at least equal to the number given in the first loop for this to work properly. How can I model this in a recursive function?
  6. You basically said the answer I came up with. Trying to do the entire operation in one step by using a url instead of a real file will not work. Instead this is what I did. Rather than try to load the url directly in to cURL as a file, run a cURL operation that calls the isset($_GET['img']) section of the code. Then instead of just displaying the image, save it wherever. At that point you'll have a real physical file you can pass to cURL. After that you can delete the file if you want. I've already changed the code a lot but it's not all that hard to figure out, it's just not as nice as if you could load a url like I was trying to do.
  7. There is probably no solution the way I was trying to do it. If anyone finds this thread and wants to know how I ended up solving it PM me.
  8. abazoskib: something like this... "@/path/file.php?img=true" I just tried using sessions so I wouldn't have to pass the variable through GET, but it's not possible because something about starting the session makes declaring a content type (image/jpeg) not work.
  9. It's pretty hard to tell exactly where the problem is coming from. You're on the right track with trying to isolate the code that's causing the problem, but I'd take that a step further and keep eliminating parts of that while loop until it works. You should start by removing the images and see if that changes anything.
  10. The line that says - echo "</td>" does not end with a semi-colon. The following should run just fine. echo "<td><strong>MP:</strong></td>"; echo "<td>"; echo "".$char['mn'].""; echo "</td>"; echo "<td><strong>Armor:</strong></td>"; echo "<td>"; echo "".$char['armor']."";
  11. This is a bit complicated, I'm just hoping someone else has run into this and knows how to do it a different way or make it work. When sending a file as part of form information included in a cURL request, it appears you can not include a query string in the file name. Take a look at my example to see what I'm talking about. //This creates an example image with some text from $_GET['img'] you can try calling this directly to see what the output looks like if(isset($_GET['img'])){ $im = imagecreatetruecolor(120, 20); $text_color = imagecolorallocate($im, 255, 255, 255); imagestring($im, 3, 3, 3, $_GET['img'], $text_color); header('Content-type: image/jpeg'); imagejpeg($im); imagedestroy($im); exit; } //Show what was sent to the $_POST and $_FILES variables if(isset($_POST['showpost'])){ echo '<pre>'; print_r($_POST); print_r($_FILES); exit; } //Here's the part where we get in trouble... //This works //$imgURL = '@'.$_SERVER['SCRIPT_FILENAME']; //This doesn't work $imgURL = '@'.$_SERVER['SCRIPT_FILENAME'].'?img=true'; $data = array('showpost' => 'true', 'file' => $imgURL); //Now do the cURL request to show information about the file that was sent $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://'.$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_exec($ch); if(curl_errno($ch)) echo curl_error($ch); curl_close($ch); When using the section that says "This doesn't work" you'll get the cURL error "failed creating formpost data". Any suggestions?
  12. That's the ticket! Thanks that was exactly what I needed :]
  13. Doesn't exactly help. Comments aren't always at the beginning of lines.
  14. I'm having trouble catching comments inside php code. Could someone help me revise my regex or tell me how I can make this work properly. My comment detection regex is: ~//.*?[\n\r]~ and ~/\*(.*?)\*/~s The problem is this... $test = 'http://google.com'; <- is not a comment! How can I get this regex so it doesn't catch anything inside strings?
  15. Yeah, I'll change it to that. It just doesn't really matter. If there's a capital within the first 3 characters it's probably the first letter of the sentence anyways.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.