Jump to content

JAY6390

Members
  • Posts

    825
  • Joined

  • Last visited

About JAY6390

  • Birthday 09/22/1984

Contact Methods

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

Profile Information

  • Gender
    Male
  • Location
    UK

JAY6390's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. $result = preg_replace('/<\?(?!php)/', '<?php', $subject);
  2. Just change the two / to be ~ and then change the two )-( to read )/(
  3. change [/b] to [\/b]
  4. ha yeah I like to keep my groups just so I know where everything is tbh, you are right though it was unnecessary. Love the one liner!
  5. <?php $str = "R1,R2-5,R7"; $parts = explode(',', $str); $out = array(); $regex = '~^([^\d]+)(\d+)-([^\d]*)(\d+)$~'; foreach($parts as $part) { if(preg_match($regex, $part, $matches)) { $range = range($matches[2], $matches[4]); foreach($range as $number) { $out[] = $matches[1] . $number; } } else { $out[] = $part; } } echo '<pre>' . print_r($out, true) . '</pre>'; ?> That's how I would do it. Should work for your last example too
  6. [^\d]+ will match everything before the numbers
  7. You aren't going to be solving this using regex, at least not all of it. You're going to need to explode the values using the , then us a regex to match the 2-5, then use a for loop to iterate over the values and add them correctly to the array
  8. are you wanting the addslashes() function?
  9. You can just put the forward slash since you're using # as your delimiter
  10. $abc = "I drink water. I drink vodka too."; $regex = '~\b(water|vodka)\b~i'; if(preg_match($regex, $abc)) { // Found a match }
  11. I'm pretty sure from this quote that its part of a full page of text
  12. Surely that would match the data between all tags on a page, not just the specific data in the span tag that the OP requested? I'm assuming the string given is only part of the page, not the whole thing
  13. Note that in my regex I used ~ ~ as the start/end delimiters, instead of / That is why you are getting an error. While using the DOM Document is great, it's probably overkill for your example
  14. ~<span id="TotalDue">([^<]+)</span>~ The value will be stored in capture group 1
  15. I was being sarcastic It's not me that needs to know how to fix the error lol
×
×
  • 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.