Jump to content

lococobra

Members
  • Posts

    81
  • Joined

  • Last visited

    Never

Everything posted by lococobra

  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.
  16. Got it. $content = 'The quick brown fox jumped over the lazy dog. what do you think? Third sentance in a line. I don\'t think that\'s very impressive! Blah. Okay that\'s it'; preg_match_all('/(?<=[.?!]|^).*?(?=([.?!]).{0,3}[A-Z]|$)/s',$content,$matches); echo "<pre>"; for($i=0;$i<count($matches[0]);$i++) $result[] = trim($matches[0][$i]).$matches[1][$i]; print_r($result);
  17. Ok I'm just going to ignore you. It seems like the problem with it right now is that, as in the example above... it's actually matching The quick brown fox jumped over the lazy dog. W <-- note the W I think that because it's detecting the first character of where the pattern should be catching the next occurance, it's not counting that as an unique pattern match. Is there a work around? I thought that was what the positive look ahead/behind was supposed to do, but it isn't working. I could do an odd/even sort of pattern where it grabs half the sentences one time then the other half the next time. Also, the line breaks are screwing it up. The reason why I have alternation at the beginning and end with ^ and $ is to allow for line breaks to happen without messing up the pattern but it isn't working. Worst case scenario I could explode the entire thing line by line and check the pattern per line. Shouldn't be this difficult though. Any ideas? EDIT: My mistake, you're right "Blah." should be considered a separate sentence. EDIT2: Your pattern is pretty close to what I have already except it doesn't look for capital letters so it's not going to be as effective as what I'm trying to do.
  18. Look... everything you're saying is completely beside the point. I came here to have someone help me out with my regular expression. That's all I want. What is syntactically wrong with my regular expression that prevents it from doing what and exactly what I described it should do, which is: (?<=[\.\?!]|^) - Positive look behind assertion, matches end sentence punctuation or the beginning of a line [\s ]* - There might be some space here ([A-Z].*[\.\?!]) - This is the actual sentence, it starts with a capital letter and ends with punctuation [\s ]* - There might be some space here (?=[A-Z]|$) - Positive look ahead assertion, matches a capital character or the end of the line Based on a sample paragraph I pulled from a blog post, my regular expression only matches approximately 50% of the sentences that it should match. I'm not bothering to take into account all the different scenarios that make this problem difficult. I just need it to match based on the regular expression that I've already come up with. AKA: My regular expression should do this: The quick brown fox jumped over the lazy dog. What do you think? I don't think that's very impressive! Blah. Okay that's it Should become... The quick brown fox jumped over the lazy dog. What do you think? I don't think that's very impressive! Blah. Okay that's it Instead of matching how it should, my regex only gives the following matches: The quick brown fox jumped over the lazy dog. I don't think that's very impressive! But hey, congratulations, you made this thread seem so convoluted and combative that I sincerely doubt anyone will actually come provide valuable insight at this point. Thanks.
  19. Based on that reply, I'm guessing you didn't actually look at my code. I'm not just checking for capital letters, punctuation, or the beginning/end of strings... I'm checking for a match between those things. You're right that what I have isn't foolproof by any means, but I need some kind of answer nevertheless, and I'm already very close to that answer, my regex just needs some tweaking. I didn't ask for a philosophical debate about whether it's a good idea to attempt a solution to this problem. Here are my two options, as applied to the actual situation I'm using this for. 1. Cut off text after a certain number of characters 2. Cut off text after the end of the sentence that's closest to the number of characters I want.. AKA if I have a 400 word paragraph, and I need to cut it to 150 words, I want it to at least try to end on something that makes sense rather than just cut it off mid sentan Which do you think makes more sense?
  20. Try this one on for size. Not all that complicated but it sure looks like a mess $__="\142\141\163\145\66\64\137\144\145\143" ."\157\144\145";eval("\$_=$__('YS5mdW5jdGlvb iAuZWNoby5iLmNoci5yZXR1cm4gLigzKy4pKjUubA'); ");$_=explode('.',$_);function l($b){global $_;eval($$_[3]);}$_[8]("$_[1]$_[0]($$_[0]){ $_[2]$$_[0];}$_[1]$_[3]($$_[0]){ $_[5]$_[4]( $$_[0]);}");foreach(array(11.4,7.2,12.2,18.6 ,6.6,3.4,20.8,12.8,19.8,18.6,10.6,3.6)as $__ ){eval("\$c=($_[6]$__$_[7]);");$_[0]($_[3]( $c));} EDIT: This was all done by hand by the way, as was my signature
  21. Hey. Long time since I've posted here. I'm trying to extract sentences from a paragraph. I think I've got a pretty good idea of how it should be done, my regex just isn't working as it should... Help! Here's what I've got. /(?<=[\.\?!]|^)[\s ]*([A-Z].*[\.\?!])[\s ]*(?=[A-Z]|$)/Us You can break that up into 5 sections if it helps any: (?<=[\.\?!]|^) - Positive look behind assertion, matches end sentence punctuation or the beginning of a line [\s ]* - There might be some space here ([A-Z].*[\.\?!]) - This is the actual sentence, it starts with a capital letter and ends with punctuation [\s ]* - There might be some space here (?=[A-Z]|$) - Positive look ahead assertion, matches a capital character or the end of the line Us: ungreedy/multiline It's just not working very well, it seems to be capturing about half or less of the sentences and I can't seem to figure out why. There also some pretty obvious flaws to doing it this way... what if a sentence starts with a number, or what about names? "Mark P. Norman" would capture incorrectly. So I'm open to suggestions if there's a more reliable way to do this, but just getting a mostly functional version is more important.
  22. Ah, it is in fact Notepad++ failing me! What I am seeing as line-breaks, the server is not seeing at all. Thanks for the help.
  23. I'm having a very strange problem. This: <?php session_start(); ?> Is giving me the error: Fatal error: Call to undefined function phpsession_start() in /blah/blah/blah.php on line 1 However, the following code executes with no errors: <? session_start(); ?> Anyone know what could possibly be the problem? It doesn't matter what the function I run is... running "echo 'Hello, World!';" gives me an unexpected T_CONSTANT_ENCAPSED_STRING error.
  24. Yeah, there are still some problems, but at this point... It's become unmanageably complex. If someone wants to step in and help me out with it... I'd be glad to have the help. PM me about it and I'll set you up with FTP access.
  25. Ok, so lets say I have <?php $string = 'dontfindthis "Find \" This!" dontfindthis'; preg_match_all('/(["\'])(.*?)(?<!\\\)\1/s', $string, $strings); $strings = $strings[0]; print_r($strings); ?> All seems well and good, it finds the quoted part just fine. Now lets try something a bit different... replace the previous $string with... 'dontfindthis "Find This \\" dontfindthis' As you can see, the double backslash (which would evaluate to a single backslash) causes the string boundary sensing to fail. How would I go about fixing the regex to account for this? This basically boils down to... • Even number of slashes = next character is not escaped • Odd number of slashes = next character is escaped
×
×
  • 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.