Jump to content

effigy

Staff Alumni
  • Posts

    3,600
  • Joined

  • Last visited

    Never

Everything posted by effigy

  1. Regular expressions are not the best tool for nested data, but this works: <pre> <?php $data = <<<DATA <custom> probe1 <custom> probe2 </custom> probe3 </custom> <custom> probe4 </custom> <custom> probe5 </custom> DATA; preg_match_all('%<custom>(??!<custom>)(?!</custom>).)*<\/custom>%s', $data, $matches); print_r($matches); ?> </pre>
  2. $sql = preg_replace("/'(\d+)'/", '$1', $sql);
  3. You have a laziness/greediness issue.
  4. ?! means does not follow. ?= means follows. ?!=, what you have, means does not follow, then a literal =.
  5. What encoding are you using?
  6. http://www.regular-expressions.info/lookaround.html
  7. Why are you using this and not a character class? This kind of alternation is not optimal.
  8. I think it's best to include the + since it doesn't hurt. If the data is coming from a user they could have a typo—"02/27//2009" for instance—which, when split, would create 4 elements rather than 3. However, if there are any delimiters on the ends, this would still create empty elements. I recommend: preg_split('/\D+/', $string, -1, PREG_SPLIT_NO_EMPTY)
  9. You can split on \D+.
  10. file_get_contents should be fine. Most editors do; I use Notepad++.
  11. <pre> <?php $tests = array( 'BBB', 'BBB; BBB', 'BBB; BBB; BBB; BBB', 'B;', ';B', ';;', ); foreach ($tests as $test) { echo "$test => "; echo preg_match('/\A([^;]+;\s*)*[^;]+\z/', $test) ? 'OK' : 'Not OK' ; echo '<br>'; } ?> </pre>
  12. <pre> <?php $data = <<<DATA HOW TO WATER ROSES Start by turning the water on.... HOW TO MOW Start the mower... DATA; print_r(preg_split('/(?:\r?\n)+/', $data)); ?> </pre>
  13. You need to use the /m modifier if you want $ to match around all new lines, rather than just the end of the string.
  14. /\Apub-\d{16}\z/
  15. What's the value of $unicode? This gives me "réréré": <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> <pre> <?php $text = 'r%C3%A9r%C3%A9r%C3%A9'; echo urldecode($text); ?> </pre>
  16. "Suddenly"? Perhaps your input and/or code changed? Have you examined the data fully? A hex dump, perhaps?
  17. You've bad Unicode. See "Replacement character" here.
  18. Your first .*? will capture anything up to prodID, even it has to go beyond another double quote or into another tag. Try |href="([^"]+prodID=[^"]+)"[^>]*>(.*?)</a>|.
  19. Are all of these Kanji? You can use their code point ranges to match them, e.g. preg_match_all('/[\x{3000}-\x{303F}]+/u', $string, $matches);.
  20. http://www.phpfreaks.com/forums/index.php/topic,190618.msg855845.html#msg855845
  21. Turn your warnings on: Warning: preg_match_all() expects parameter 2 to be string, array given. You need to examine the results; I recommend print_r($byname);
  22. Even better, be specific: '/href="([^"]*)"/i' The double quotes were escaped in the regex because they were used to delimit the string; they will match an unescaped quote: <pre> <?php $str = '"'; echo preg_match("/\"/", $str); ?> </pre>
  23. Apparently it requires the delimiter: preg_match('/' . preg_quote($start, '/') . '(.*?)' . preg_quote($end, '/') . '/', $data, $matches);
  24. /(\b(?!(?:else)?if)\S+\b\s*\()/
×
×
  • 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.