Jump to content

.josh

Staff Alumni
  • Posts

    14,780
  • Joined

  • Last visited

  • Days Won

    43

Everything posted by .josh

  1. What?
  2. Right. The regex is looking for digits (numbers) 'black' is not a number. try color=(.*) or color=(a-zA-Z)
  3. laundering counterfeit money.
  4. okay well first off, you say in the OP you're trying to spit out info, not put it into an array. You just explained how you were having issues trying to spit out info from an array. To me, that means you're trying to spit out info, not put info into an array. 2nd, it's print_r, not print_f.
  5. Or hey, just do this: <?php echo "<pre>"; print_r(get_defined_vars()); echo "</pre>"; ?>
  6. Well it looks like you already have your idea. Now break it down and start coding. Google how to make an iframe. Google how to make a form. Google how to use submitted form values. Google how to print variables to the screen.
  7. If you're just wanting a dump of info for debug purposes, just do something like <?php $ArrayList = array("_POST", "_GET", "_COOKIE", "_ENV", "_FILES", "_SESSION", "_SERVER"); foreach($ArrayList as $gblArray) { echo "$gblArray<br/>"; echo "<pre>"; print_r($$gblArray); echo "</pre>"; } ?>
  8. I originally posted my take on it in the thread but decided to remove it due to me feeling like I would be helping him cheat, and offered up some advice instead. Since I'm fairly sure the guy isn't going to randomly walk into this thread in this forum, I'll post what I came up with here. I'm not all that great at coding and I'm sure there's more clever ways to do it, and in fact, I know I can streamline it a bit already, but anyways... <?php // array of example acronyms/meanings $examples = array( "RADIUS" => "Remote Authentication Dial In User Service", "TCP/IP" => "Transmission Control Protocol / Internet Protocol", "FedExDel" => "Federal Express Delivery", "Bigpost" => "Big Post", "R.I.P." => "Rest In Pieces", "Cisco" => "San Francisco", "ragnat" => "Teragen International"); /*** function to determine what type, if any, the acronym is. ***/ function findAcronymType($acronym, $meaning) { /*** If there is a special char somewhere, get rid of it ***/ // array of special chars. Feel free to add to it $sChars = array('/','.'); // remove each special char foreach ($sChars as $val) { $acronym = str_replace($val,'',$acronym); $meaning = str_replace($val,'',$meaning); } // end foreach // get rid of extra whitespace in acryonym $acronym = str_replace(' ','',$acronym); // get rid of extra whitespace in meaning $meaning = explode(' ',$meaning); foreach ($meaning as $key => $val) { if (trim($val) == '') unset($meaning[$key]); } // end foreach $meaning $meaning = implode(' ',$meaning); /*** end get rid of special chars ***/ // *** check if type Simple *** // get rid of caps $tAcronym = strtolower($acronym); $tMeaning = strtolower($meaning); // make some arrays $tAcronym = str_split($tAcronym); $tMeaning = explode(' ',$tMeaning); // loop through each word in meaning and // chop everything off except first letter foreach ($tMeaning as $key => $val) { $tMeaning[$key] = substr($val,0,1); } // end foreach $tMeaning // if the two arrays match, we have a winner! if ($tAcronym == $tMeaning) { return "Simple"; } // *** end check if type Simple *** // *** check if type Complex *** // get rid of caps $tAcronym = strtolower($acronym); // get rid of caps and make an array of words $tMeaning = explode(' ',strtolower($meaning)); // loop through each word in meaning, starting // with last word, ending in first for ($mPos = count($tMeaning)-1; $mPos >= 0; $mPos--) { // found out how many letters are in the acronym $cALen = strlen($tAcronym); // loop from 0 to however long the acronym is for ($aPos = 0; $aPos < $cALen; $aPos++) { // idea here is to take the acronym vs. word and // slice off letters at beginning of acronym, end of word // and compare the result. $aRange = substr($tAcronym,$aPos, $cALen); $mRange = substr($tMeaning[$mPos],0,$cALen-$aPos); // if we have a match... if ($aRange == $mRange) { // chop off the matched part off the end of acronym, so // next loop iteration will use what's left of the acronym and go from there $tAcronym = substr($tAcronym,0,-strlen($aRange)); // store the match in an array and break out of this current loop iteration $match[$mPos] = $aRange; break; } // end if } // end for // if any of the iterations do not yield a match, no point in // continuing the loops, as it will not be a complex acronym if (!$match) break; } // end for // if we have some results... if (is_array($match)) { // sort them (remember, we started back to front) ksort($match); // make a string out of the array $match = implode('',$match); // compare the result to the acronym. If they match, we have a winner! if (strtolower($acronym) == $match) { return "Complex"; } // end if } // *** end check if complex *** // *** check if type Substring *** // get rid of caps $tAcronym = strtolower($acronym); $tMeaning = strtolower($meaning); // make an array of letters form acronym $tAcronym = str_split($tAcronym); // wrap all the letters up with "match everything" regex $tAcronym = "(.*)" . implode("(.*)",$tAcronym) . "(.*)"; // check if the acronym can be linearly spelled out in the meaning // if it can, we have a winner! if (preg_match("/" . $tAcronym . "/",$tMeaning)) { return "Substring"; } // *** end check if type Substring *** /*** Invalid acronym/meaning type ***/ // If we have gotten this far, then we do not // have a real acronym/meaning pair. return "Acronym and Meaning do not match."; // *** End invalid type *** } // end function findAcronymType // example loop to loop through the example acronyms/meanings foreach ($examples as $acronym => $meaning) { echo "$acronym : $meaning -> " . findAcronymType($acronym, $meaning) . "<br/>"; } // end foreach $examples ?>
  9. Well if you want something to do for the next couple hours, here's a question for you: http://www.phpfreaks.com/forums/index.php/topic,225103.0.html That was a fun one for me to solve
  10. oops. didn't notice that. apparently doing mysqli.query works.
  11. Yeah I don't really care for () enforcement either, but php.net seems to parse them the same, with or without, so I'm not complaining. Just glad to have a shorttag for it.
  12. I would like to see regular competitions happen, but as Dan said, there wasn't enough interest. Ideally, I would like to for us to regularly host competitions in which there is an entry fee required. One of the problems with the competitions in the past was people signing up and then dicing out, even though we made very large, colored and bolded statements about not signing up unless you were seriously for really real serious about doing it. It's a waste of everybody's time when people don't follow through. Requiring an entry fee ensures that people who enter are serious about following through instead of dicing out. Another problem was lack of rewards. We're all volunteers here. We don't get paid for doing any of this, and although we get some donations here and there, it goes straight towards hosting/server costs, and afaik it nowhere near covers those costs. The owner of phpfreaks.com pays most of it out of pocket. Only reason we're still even around is that he gets to write it off as a business expense for his real job (I think). Point is, there isn't any money laying around to be coming up with prizes. We've gotten some offers here and there for people willing to donate prizes (hosting packages, mostly), but it wasn't steady and reliable. By requiring an entry fee, we can take that money and come up with prizes. Another reason the contests failed was because the judges dragged ass when it came to judging. Though I think that was a result of prizes being sucky and shady and people dicing out to begin with. By the time all that happened, I think the judges caught a "why bother?" attitude. I think that having an entry fee would indirectly solve this problem, as well. Also, I think the contest challenges were too long. The code itself wasn't really that hard to wrap one's head around. Just a whole bunch of little things that add up to having a long project to do. And on top of that, we would give the people like 1-2 months to do it. Virtually every contest idea brought to the table involved doing things that took a long time to do. I think if we were to consider running contests again, the challenge and contest duration would have to be significantly smaller.
  13. Simple Acronym Simple acronyms are fairly easy to figure out. The idea is to check to see if you have an equal amount of letters in the acronym as words in the meaning, and then check to see if each acronym letter corresponds to the first letter in each word. There are several ways you can accomplish that. One way is for you to explode the meaning into any array, loop through each word and use substr to build a string of each of the first letters, and then compare that to the acronym. Hint: Before anything else, get rid of special characters like dots and slashes. Some acronyms use them (like TCP/IP or M.A.S.H.). A Simple str_replace should (mostly) do the trick. Substring Acronym Substring Acronyms are the easiest to figure out. All you really have to do is str_split the acronym letters, then implode it back into a string, with a "match everything" regex as the glue (be sure to add the regex to the beginning and end, as well). Then simply use preg_match to see if you've got a winner. Hint: This is the last acryonym type you will want to check for, because it will match any of the other types, as well. Technically, all Acryonyms are substring acronyms. Complex Acronym Complex Acronyms are (maybe just IMO) the hardest to figure out. At first look, it seems like it should be fairly easy. Especially if people do you a favor and capitalize the acronym in the "right" places (like FedEx). Unfortunately, that might not always be the case (like in Bigpost). And you can't just loop through each letter of the acronym, check if there's a match with the current word, move on to the next word when the match stops. Why? Take a look at FedEx, for example. If you were to do it that way, you would end up matching FedE in the first word, and then your script would then try to look for 'x' as the first letter of the next word, instead of the intended 'e.' So what can you do? Hint: Here is some info echoed out inside of some loops. I even used a 3 word acronym as an example for more output: ("FedExDel" => "Federal Express Delivery") Well there you have it. Good luck with figuring out your homework.
  14. Edited to remove code. It was an interesting problem to solve (which, afaik it seems to work just fine), but it turns out I feel like if I give you my code I would be helping you cheat, so as much as I'd like to post my code for bragging rights, I can't. I do, however, feel it would be okay for me to point you in the right direction, as far as what I did. I'll be posting that shortly.
  15. Well I've worked out how to tell if it's a simple or substring acronym, still working on complex.
  16. smf is a php scripted board, and we're a php community. Any one of us can make a mod for that, ourselves. We just prefer that something be put into the core, instead. Especially when it comes to a feature that should obviously be an option, not just some random bling thing.
  17. haha yah don't do that, I was just showing blade something.
  18. Sure you have. Or at least, you've seen the principle. $result = mysql_query($sql) or die(); Same principle.
  19. You can't. Make a post in the smf community for a "Mark as Read Forever" option. Please. I beg you.
  20. You can indeed use && or AND in mysql (and php). They have different orders of operation though.
  21. possibly try html_entity_decode on it if that don't work it's probably the receiving mail server doing it not a whole lot you can do about that. I'm totally pulling sh!t out my arse so don't praise me if it actually works
  22. another: <?php $x = "$1,345.45"; $x = preg_replace("/[$,.]/","",$x); echo $x; ?>
  23. probably a better way, but here's my take: <?php $x = "$2,343.23"; sscanf($x,"$%d,%d.%d",$num[0],$num[1],$num[2]); $y = implode('',$num); echo $y; ?>
  24. Okay seriously, stop with the posting of syntax errors. Syntax errors are like spelling errors. The error tells you exactly what to do. There's no reason why you shouldn't be able to figure that out. Especially if you use an editor that has code highlighting.
×
×
  • 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.