Jump to content


Staff Alumni
  • Posts

  • Joined

  • Last visited


About effigy

  • Birthday 05/07/1981

Profile Information

  • Gender
  • Location

effigy's Achievements


Member (2/5)



  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. http://www.regular-expressions.info/lookaround.html
  6. Why are you using this and not a character class? This kind of alternation is not optimal.
  7. 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)
  8. file_get_contents should be fine. Most editors do; I use Notepad++.
  9. <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>
  10. <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>
  11. You need to use the /m modifier if you want $ to match around all new lines, rather than just the end of the string.
  • 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.