0

I have the following string:

$db_string = '/var/www/html/1_wlan_probes.db';

I want to isolate/strip the number character so that I only have the following left:

$db_string = '1';

So far I havn't found an simply solution since the number that needs to be found is random and could be any positive number. I have tried strstr, substr and custom functions but none produce what I am looking after, or I'm simply overlooking somehthing really simple.

Thanks in advance

TarikM
  • 25
  • 7

1 Answers1

0

You should use the preg_match() function:

$db_string = '/var/www/html/1_wlan_probes.db';

preg_match('/html\/(\d+)/', $db_string, $matches);

print_r($matches[1]); // 1

html\/(\d+) - capture all the numbers that come right after the html/

You can test it out Here. It does not matter how long the number is, you're using a regular expression to match all of them.

Mihailo
  • 4,736
  • 4
  • 22
  • 30