Jump to content

[SOLVED] how to extract numbers out of a string


ballhogjoni

Recommended Posts

2 ways. Not sure which is faster...

 

<pre><?php

$str = 'https://www1.xxxxxxxx.com/partners/links/cardholders/details.asp?idmin=45621&tempid=568261';

parse_str( parse_url($str, PHP_URL_QUERY), $queryArray );

echo $queryArray['idmin'];

?></pre>

 

or

 

<pre><?php

$str = 'https://www1.xxxxxxxx.com/partners/links/cardholders/details.asp?idmin=45621&tempid=568261';
$expr = '%idmin=(\d++)%';

preg_match( $expr, $str, $match );

echo $match[1];

?></pre>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.