Jump to content

effigy

Staff Alumni
  • Posts

    3,600
  • Joined

  • Last visited

    Never

Everything posted by effigy

  1. It made unwanted modifications; observe: The following is an emoticon: =o) The following is a formula: a=b*c The following is an emoticon: =) The following is a formula: a=*c
  2. It depends on the data. I think it's a safer approach because we're making two verifications rather than one: (1) the data must appear after an equals sign; and (2) the data must appear before a double quote. Otherwise, it could botch up something like this: <pre> <?php $str = '<H1=2D"some_value">The following is an emoticon: =o) The following is a formula: a=b*c'; $str = preg_replace('#(?<==)\w+#', '', $str); echo $str; ?> </pre>
  3. $str = preg_replace('#(<[^=>]+=)(\w+)("\w+">)#', '$1$3', $str); I added > to the character class so it will not match into another tag should the originating one not have an equals sign. There's no need for /e. Another approach with less captures, should it fit the context of the data: $str = preg_replace('#(?<==)\w+(?=")#', '', $str);
  4. effigy

    split string

    <pre> <?php $tests = array( 'username:password@host', 'username:password@host:port/username', 'username:password:username@host:port/username', ); foreach ($tests as $test) { echo "<b>$test</b><hr>"; $pieces = preg_split('%?=[^@]+\z)%', $test); print_r($pieces); } ?> </pre>
  5. <pre> <?php $data = <<<DATA <HTML> <HEAD> </HEAD> <body> <table align="center" width="771" height="166" border="0" cellpadding="0" cellspacing="0"> <tr> first</tr> <tr> second</tr> </table> <table> <tr>matchthis</tr> </table> </BODY> </HTML> DATA; preg_match('%<table[^>]*>(??!</table>).)*?matchthis.*?</table>%s', $data, $matches); print_r(htmlspecialchars($matches[0])); ?> </pre>
  6. You must escape / because it is also serving as the pattern delimiter. <pre> <?php $str = '16cm, 2 columns 1/2'; preg_match_all('%\d+(?:[\./]\d+)?%', $str, $matches); foreach ($matches[0] as &$match) { if (strpos($match, '/') !== FALSE) { list($num, $den) = explode('/', $match); $match = eval("return $num / $den;"); } } echo $product = array_product($matches[0]); ?> </pre>
  7. Will you be making many changes? parse_ini_file may be the better approach.
  8. http://www.phpfreaks.com/forums/index.php/topic,127902.0.html
  9. /\d+(?:\.\d+)?/
  10. NODE EXPLANATION ---------------------------------------------------------------------- \b the boundary between a word char (\w) and something that is not a word char ---------------------------------------------------------------------- (?: group, but do not capture: ---------------------------------------------------------------------- Name 'Name' ---------------------------------------------------------------------- | OR ---------------------------------------------------------------------- Player 'Player' ---------------------------------------------------------------------- | OR ---------------------------------------------------------------------- Ally 'Ally' ---------------------------------------------------------------------- | OR ---------------------------------------------------------------------- Town size 'Town size' ---------------------------------------------------------------------- ) end of grouping ---------------------------------------------------------------------- : ':' ---------------------------------------------------------------------- \s* whitespace (\n, \r, \t, \f, and " ") (0 or more times (matching the most amount possible)) ---------------------------------------------------------------------- \S+ non-whitespace (all but \n, \r, \t, \f, and " ") (1 or more times (matching the most amount possible)) ----------------------------------------------------------------------
  11. You mean a total of the totals? Create an array for the totals, push each one on, and use the same array_product approach array_sum.
  12. Here's a start: <pre> <?php $data = 'Ikariam Live the ancient world! You are here: World > Adatia[42:85] Info Attention: This area of the page is updated when you select a town! Actions Attention: This area of the page is updated when you select a town! Towns on Adatia * Guangzhou (i) o Name: Guangzhou o Town size: 17 o Player: DarthExile Send Message o Ally: - o Diplomacy o Transport goods o Pillage o Blockade harbor o Send out spy * Building ground * SG-1 o Name: SG-1 o Town size: 13 o Player: wj0912 Send Message o Ally: WRL Send Message o Diplomacy o Transport goods o Pillage o Send out spy * Oceanside (u) o Name: Oceanside o Town size: 16 o Player: Gunner08 Send Message o Ally: - o Diplomacy o Send out spy * Building ground * Sphinx o Name: Sphinx o Town size: 20 o Player: Bean Send Message o Ally: WRL Send Message * beercity o Name: beercity o Town size: 21 o Player: Cyclops Send Message o Ally: WRL Send Message o Diplomacy o Transport goods o Pillage o Send out spy * 004 o Name: 004 o Town size: 8 o Player: rjrsson Send Message o Ally: WRL Send Message o Diplomacy o Transport goods o Pillage o Send out spy * Hoodville 2 (u) o Name: Hoodville 2 o Town size: 17 o Player: Sniped2 Send Message o Ally: - o Diplomacy o Send out spy * Christopilis (i) o Name: Christopilis o Town size: 11 o Player: WRLChris Send Message o Ally: WRL Send Message o Diplomacy o Transport goods o Pillage o Send out spy * LOLbeer (i) o Name: LOLbeer o Town size: 13 o Player: redratfish Send Message o Ally: WRL Send Message o Diplomacy o Transport goods o Pillage o Send out spy * New Zlin o Name: New Zlin o Town size: 20 o Player: WRLPeer de Beer Send Message o Ally: WRL Send Message o Diplomacy o Transport goods o Pillage o Send out spy * Building ground * hydro man o Name: hydro man o Town size: 17 o Player: terrinater Send Message o Ally: WRL Send Message o Diplomacy o Transport goods o Pillage o Send out spy * New Dystopia o Name: New Dystopia o Town size: 20 o Player: JangosAgony Send Message o Ally: WRL Send Message o Diplomacy o Transport goods o Pillage o Send out spy * king of saians (u) o Name: king of saians o Town size: 21 o Player: rogobodo Send Message o Ally: WRL Send Message o Diplomacy o Send out spy Special places on Adatia * Forest * Vines * Colossus Imprint Town navigation * Current town: [42:85] Sphinx o [42:82] Manticore o [43:84] Gryphon o [42:85] Sphinx o [43:85] Dune o [45:84] Osheanus * Previous Town * Next Town * Show World * Show Island * Show Town Resources of your Empire * Trade ships: 0(51) * Gold: 570,466 * Income: 234 Town´s resources * Population: 777 (1,878) * Action Points: 6 * Building material: 12,742 Storage capacity: 81,024 * Wine: 7,263 Storage capacity: 35,232 * Marble: 2,795 Storage capacity: 35,232 * Crystal Glass: 143 Storage capacity: 35,232 * Sulfur: 10,000 Storage capacity: 35,232 Overviews * Towns To Overview * Military To Overview * Research To Overview * Diplomacy To Overview © 2008 by Gameforge. All rights reserved. Rules T&Cs Imprint Other Options * Help * Ikariam PLUS (0) * Highscore * Options * Board * Logout * v.0.2.7 * 25.08.2008 23:38:52'; preg_match_all('/\b(?:Name|Player|Ally|Town size):\s*\S+/', $data, $matches); print_r($matches); foreach ($matches[0] as $match) { list ($key, $value) = explode(': ', $match); echo "$key/$value<br>"; } ?> </pre>
  13. No stripping is needed: <?php $str = '16cm, 2 columns'; preg_match_all('/\d+/', $str, $matches); echo $product = array_product($matches[0]); ?>
  14. It only covers -, a-z, white space, ., ?, and !. Is that enough? No one is going to throw in @, #, $, %, &, *, etc? The parens are not needed: #[-a-z\s.?!]+#i.
  15. Try /^[^=\s]+\s*=\s*.+$/m.
  16. That's it as is? It has no line breaks?
  17. Be where? I used a function in my example because I didn't have an include. Whatever functions you call have to exist.
  18. I use it in all of my examples because it's oftentimes required for printing arrays and such; see http://www.w3schools.com/TAGS/tag_pre.asp. You can disregard. Yes.
  19. <pre> <?php $string = "Woo, [countdown]1230163200[/countdown] until Christmas. That means its [countdown]1230768000[/countdown] until 2009."; function countdown ($in) { ### Calculations here. return $in; } echo preg_replace('%\[countdown\](.*?)\[/countdown\]%e', 'countdown("$1")', $string); ?> </pre>
  20. Will there be only one pair, or multiples?
  21. Anything after the ending delimiter is considered a modifier.
  22. How about something generic like this? <pre> <?php $data = "I'm using preg_match_all. Sorry, I'm just not familiar with regex because I usually just google what I need. But overall I just need to find a regex to locate emails with and without parenthesis around it. e.g. [email protected] and ([email protected])."; preg_match_all('/\b[^@\s]+@\S+?\.[a-z]+\b/i', $data, $matches); print_r($matches) ?> </pre>
  23. Why so many parentheses? What preg_ function are you using? Are you using the matches?
  24. For more Perl information see learn.perl.org or perlmonks.org. You can also try our Other Languages board, but it is nowhere as comprehensive.
  25. Thank you, but the credits go to YAPE::Regex::Explain.
×
×
  • 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.