Reputation:
I was wondering how to grab some text from an external page using PHP. I think that preg_match() can help but I can't get how to use it.
The text in the page is the following:
dragontail-5.7.2.tgz
and I need to grab only
5.7.2
Thank you for helping.
Upvotes: 1
Views: 46
Reputation: 338
Check this out: https://regex101.com/r/cF8mS1/1
/([0-9.]+)/gm
Means "Select all the integer characters since they are more than 1, and include the "." as well, and give me all of them, on multiline too. Thank you." The last thing to do is to delete the last or first character ".", so:
if (preg_match('/([0-9.]+)/gm', $input, $matches)) {
$result = trim($matches[1], '.');
} else {
$result = null;
}
Upvotes: 1