Jump to content


Staff Alumni
  • Posts

  • Joined

  • Last visited


Everything posted by nrg_alpha

  1. Looks good Dan! [ot]I still think it looks good![/ot] Thanks for the implementation!
  2. I could just see Apple fanboys holding hands and laughing / dancing at our win PC expenses (unless Macs have their fair share of similar issues - I wouldn't know.. I'm not a Mac user [yet]).
  3. Getting an array as a result is normal (with preg_match_all, the results will be stored into array index 0) like so: $blogcontent = <<<EOF --------Start Blog----------- If you wanna learn how I create this website, you can start by reading some of the material in the below link. This is how I got started on creating website. [weblink]www.htmlcodetutorial.com[/weblink] I can show you what I know. More text [weblink]www.htmlcodetutorial2.com[/weblink] followed by yet more text. --------End Blog------------- EOF; preg_match_all('#\[weblink]([^[]*)\[/weblink]#', $blogcontent, $matches); echo '<pre>'.print_r($matches[0], true); // this is the info you seek I suppose you could always use a preg_replace callback to do the replacements: Example: $blogcontent = <<<EOF --------Start Blog----------- If you wanna learn how I create this website, you can start by reading some of the material in the below link. This is how I got started on creating website. [weblink]www.htmlcodetutorial.com[/weblink] I can show you what I know. More text [weblink]www.htmlcodetutorial2.com[/weblink] followed by yet more text. --------End Blog------------- EOF; function replacement($input){ return $input[0] = "<a href=\"$input[1]\">$input[1]</a>"; } $blogcontent = preg_replace_callback('#\[weblink]([^[]*)\[/weblink]#', 'replacement', $blogcontent); echo $blogcontent; If the weblink tags can be upper or lowercase, you can always throw an 'i' modifier after the closing delimiter to match it in any case (upper or lower).
  4. \D = a character that is not a digit (the inverse of \d if you will)
  5. The keyword here is indeed (arguably), as I think the speed of output when comparing double to single quotes is dependant on which version of PHP you're using. I think 5.2.x has single quotes executing faster.. but in the following test in 5.3, double quotes seems faster: $loop = 50000; $time_start = microtime(true); for($a = 0; $a < $loop; $a++){ echo "<a href=\"syntax\"></a>"; } $time_end = microtime(true); $elapsed_time1 = round($time_end-$time_start, 4); $time_start = microtime(true); for($a = 0; $a < $loop; $a++){ echo '<a href="syntax"></a>'; } $time_end = microtime(true); $elapsed_time2 = round($time_end-$time_start, 4); echo "Using double quotes: " . $elapsed_time1 . "<br />\n"; echo "Using single quotes: " . $elapsed_time2; Run the test a couple of times to see a better average of what numbers are being reported. Granted, in real world applications, the speed difference is going to be infinitesimal, I'm sure. Notice the loop count... not much of a difference when all is said and done.
  6. One caveat about censorship... be aware of the Clbuttic mistake. (Clbuttic derives from censoring say 'ass' with 'butt', but as a result, a word like Classic becomes Clbuttic). I would strongly consider making use of word bounderies (\b) in regex patterns for this sort of thing.. otherwise you may well end up censoring parts of legit non profanity words. **digs up older code** Where $txt is the body of text in question, here is what I did (quite a while back) for matters like this. Example: $txt = preg_replace(array('#(\b)?fuck(?:ers?)?(?(1)\b)#i', '#\bbitch(?:y|es)?\b#i', '#\bbastard\b#i', '#(\b)?asshole(?(1)\b)#i', '#(\b)?whore(?(1)\b)#i', '#(\b)?cock(?(1)\b)#i', '#\banal\b#i', '#\banus\b#i', '#(\b)?cunt(?(1)\b)#i', '#(\b)?penis(?(1)\b)#i', '#\bshit(?:[ys]|ty|t?er|t?ier?|t?iest)?\b#i', '#\bslut\b#i','#(\b)?dicks?(?(1)\b)#i', '#\bpuss(?:y|ies?)\b#i', '#\bcum\b#i', '#\bfag(?:s|gots?)?\b#i', '#\bass\b#i', '#\bbullshit(?:t?er)?\b#i', '#\bpricks?\b#i', '#\btit(?:s|ty|ties?)?\b#i', '#\basswipes?\b#i'), '*', $txt); Granted, this replaces the entire word with an asterisk.. and again, the code's a tad on the old side (it was at this point in time I was still learning regex - ok, I mean, there is always more to learn, so I am STILL learning regex, but you know what I mean.. so I was also just getting the hang of regex conditionals and tested that out - the point of using conditionals is to catch a word that is either by itself, or in combination with another one, like whore, or whoreface for example), but seems to do the trick. It takes into account word combinations as well (like bitch, bitch(y), bitch(es) kind of thing..). This code is by no means 'bulletproof'. So I reserve the right to be wrong You may find words that this thing missed, but could be used as a starting point. You would have to muck around to make modifications if you want to change the end results if the current setup is not desirable.
  7. Hmm.. using a for loop within a foreach like that? Kind of strange. You can simply tap into $matches[0] instead. Also note that you can simplify the pattern by using the 'i' modifier: $string="@welcome @decide @homicide @loser doit andlaugh"; preg_match_all('#@[a-z0-9]+#i', $string, $matches); foreach ($matches[0] as $val) { echo "matched: $val<br />\n"; }
  8. I suppose the reason why I feel the off-topic quote style boxes stand out is due to its border colour (redish, which stands out more than the typical quote box imo - I think I would have gave the entire ot body a faded redish colour (lighter than the background body) as well.. but that's just me).
  9. Hmm.. yeah, but having a side note or off-topic panel that is presented differently (coloured differently perhaps) could help stand out more, or just to help differentiate itself would be cool (without needing to fuss with quotes from OFF-TOPIC lol).
  10. I'm wondering if we could have some bbc tags like: [ot]Off Topic quote-style box here[/ot] or perhaps a [sn]Side Note quote-style box here[/sn]. I have seen this done over at sitepoint (they use [ot][/ot] for off topic). I have seen this SMF mod, but admittedly, seems cumbersome typing in [off-topic]...[/off-topic] as opposed to the ot abbreviation imo. Not sure what the parsed end result looks like.. but I do like how sitepoint presents theirs. Could come in handy for extra explanations in a post that help stand standout as opposed to just blending in with the rest of the topic's text.
  11. Hmm.. I wonder how interesting things could get from this court case: http://www.computerworlduk.com/management/government-law/legislation/news/index.cfm?newsid=16847&pn=1 The issue at hand is when someone purchases a software license, then later on wants to sell that license to someone else. Some software companies do allow this practice, while others don't. Autodesk happens to be one of those companies that do not allow the resale of licenses. Turns out that some guy named Timothy Vernor tried to sell his Autodesk license on ebay, only to have software products listed for sale removed and asked to have his account banned. An excerpt from the link (from Vernor's lawyer): I wonder how many of you guys have purchased software in the past and tried to resell it, only to find out it could not be resold. I wonder what effects the results from this court case will have (which my understanding is that the court has ruled in favor of Mr.Vernor) if an appeal from Autodesk ends up backfiring. This is an American case.. so perhaps it is restricted to the U.S. But surely many companies must be eyeing this thing carefully to see what the ultimate outcome is, and what kind of ramifications it will have on their own licensing policies.
  12. In it's rawest form: $str = 'blah 1,234 more blah'; preg_match('#(?:\d,)?\d{3}#', $str, $match); echo $match[0]; However, if it encounters a number like 1234, it will match 123 (which I assume is not desirable). So perhaps we can also make use of a conditional and \D: $str = 'blah 1,234 more blah'; if(preg_match('#\D(?:\d,)?\d{3}\D#', $str, $match)){ echo $match[0]; } else { echo 'No proper format found.'; } But I suppose this highly depends on the circumstances of where the 3 or 4 digit number is situated within the string. If the numbers are at the beginning of the string, the initial \D will throw it off. If that's the case, the pattern could be amended to: #(^|\D)(?:\d,)?\d{3}\D# In either case, I noticed you made use of the 'i' modifier, which is not usable in your example, as this is case insensative.. but since you are using digits and commas, the 'i' doesn't perform anything. EDIT - An even more refined method based off the last one: if(preg_match('#(?:^|\D)\K(?:\d,)?\d{3}(?=\D|$)#', $str, $match)){ This will now match those numbers at the start or at the end of a string.
  13. What that second line does is use strpos to check to see if the character sequence '/me ' is there and starts at position 0 in the string (therefore, the beginning of the string). If so, then $message will be equal to itself starting at position 4 (which comes right after the space after /me) by use of substr, otherwise, it is simply equal to itself (nothing has changed). Hopefully I explained that adequately. EDIT - And of course, this is all done in a ternary operator fashion...as opposed to the typical if(...){ ... } else { ... }
  14. Alternatively, Example: $message = "/me is here!"; $message = (strpos($message, '/me ') === 0)? substr($message, 4): $message;
  15. Given the turn in conversation, I'm just waiting to see CV jump in with the involvement of post apocalyptic zombies.
  16. http://bumptop.com/ Gimicky? Sure (I don't consider it to be 'practical' by any measure)... makes for something a little more interesting / entertaining than the typical desktop however.
  17. <overthinking> Well, since you describe walls and ceiling, you don't mention a floor.. therefore, I can only deduct that the room is perhaps floorless (e.g. you build your walls and ceiling structure, but no floor, thus letting the ground act as one)? If so, and depending on where this structure is located (like say hanging half way off a mudslide-ridden terrain due to torrential rain falls), one could simply drop out through the exposed bottom? (take the table with you if you can so that when you are in the raging river, you can turn it upside down and hopefully paddle your way to shore? :-\ </overthinking>
  18. [quote author=sqlnoob link=topic=54859.msg1262240#msg1262240 date=1251885056] none of the above don't use any of them i only use notepad and winsyntax [/quote] Trying to elicit 'torch and pitchfork' responses from the masses? ;)
  19. [quote author=roopurt18 link=topic=54859.msg1236983#msg1236983 date=1248863137] + It defaults to spaces over tabs for indents [/quote] I prefer tabs over spaces personally (and if I'm not mistaken, I think it saves on filesize that way as well). I use NetBeans as my IDE of choice. For me, it's a bunch of the small details that make a nice impact. + Using classes for instance, hitting Alt + Insert (with your cursor placed inside a class) brings up a panel of methods (accessor methods [if your class properties are already defined]) as well as constructor, database connections and whatnot which you can auto insert ([i]nice[/i]). + variable names come up in a pop up when typing $this-> or when calling a function (after opening parenthesis, hit Ctrl + space to list any previously declared variables). + Macros are a god send. Simply bind chunks of template code to whatever keys and presto! Saves some typing. + Keyboard shorcuts like Alt + Shift + F auto formats selected code and Ctrl + E deletes lines of code (stuff like that... not game changers to be sure, but the devil is in the details imo). Just some of the stuff off the top of my head. Yeah, it's a damn fine IDE to be sure.
  20. I highly doubt a research institute would use such a computer for games. Who knows what their going to actually use it for (perhaps complex particle physics simulations for example?), but I'd wager that using it to to play a few rounds of Unreal Tournament or Crysis wouldn't exactly be on the task list. I started reading the comments page for that article.. While I don't use Vista, I had to laugh at this one: Some people are such smart asses lol
  21. Yeah, for strings that short, either solution (along with go knows how many more are out there) will do. Please flag this thread as 'Solved'.
  22. I would think the one using strtr would probably be faster, as string functionality outstrips regex in raw speed (but in truth, the amount of text would have to be quite huge to start seeing the speed differences between the two methods.. so for modest text, it probably doesn't really matter much I'd guess).
  • 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.