0

What's a quick way for matching the following in a multiline string using preg_match?

id=334534534

id= is constant. The digits are what I need to extract.

1 Answer 1

2

The regexp'll be something like this: /id=(\d+)/im

Where the / are the reg exp delimitators, the i means "case insensitive" and m means "multi-line".

With preg_match_all() you can do this:

$subject = "YOUR STRING HERE";
$pattern = '/id=(\d+)/im';

preg_match_all($pattern, $subject, $matches);
print_r($matches);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.