Jump to content

nrg_alpha

Staff Alumni
  • Posts

    2,441
  • Joined

  • Last visited

    Never

About nrg_alpha

  • Birthday 07/14/1972

Contact Methods

  • Website URL
    http://www.olsenportfolio.com/

Profile Information

  • Gender
    Male
  • Location
    Canada's Capital

nrg_alpha's Achievements

Advanced Member

Advanced Member (4/5)

0

Reputation

  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;
×
×
  • 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.