Matching a multiple lines pattern via PHP’s preg_match()

If you’re looking for (e.g.) a h2 tag nested within a td tag where there’s only whitespace in between the two, just use \s which includes spaces, newlines, etc. eg:: preg_match(‘#<td>\s*<h2>(.*?)</h2>\s*</td>#i’,$str,$matches); // result is in $matches[1] See it in action here. For your interest, here is a list of different modifiers you can pass in … Read more

Regex to match an IP address [closed]

Don’t use a regex when you don’t need to 🙂 $valid = filter_var($string, FILTER_VALIDATE_IP); Though if you really do want a regex… $valid = preg_match(‘/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\z/’, $string); The regex however will only validate the format, the max for any octet is the max for an unsigned byte, or 255. This is why IPv6 is necessary – … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)