I have a string with a link looking like this:
$message = 'Text before link ... www.website.com/verify/12345/ ... text after link.';
After doing a if(str_contains($message, 'verify')) I now want to find the number 12345. The number can be any other number and can be of different length.
One way I could think of is to somehow get the complete link, explode with '/', and then the numbers should be the last or next to last part of the resulting array.
- Is there a better way of finding the number?
- If not, how can I retrieve the complete link from the string to then explode it?
For point two I first thought of exploding the entire string with ' ' (space) and then loop through until I find one containing 'verify', but this can be inefficient since the message can be very long. Then I though of using substr($message, mb_strpos($message, 'verify') + 7, $length_of_number); but since the number can vary in length I don't know what to put for $length_of_number.