ballhogjoni Posted September 26, 2008 Share Posted September 26, 2008 I have this string: https://www1.xxxxxxxx.com/partners/links/cardholders/details.asp?idmin=45621&tempid=568261 How can I get the numbers 45621 out of the string? Note: the numbers are dynamic so they change all the time. Link to comment https://forums.phpfreaks.com/topic/125885-solved-how-to-extract-numbers-out-of-a-string/ Share on other sites More sharing options...
redarrow Posted September 26, 2008 Share Posted September 26, 2008 <?php $url="https://www1.xxxxxxxx.com/partners/links/cardholders/details.asp?idmin=45621&tempid=568261"; echo $_GET['idmin']; ?> Link to comment https://forums.phpfreaks.com/topic/125885-solved-how-to-extract-numbers-out-of-a-string/#findComment-650933 Share on other sites More sharing options...
ballhogjoni Posted September 26, 2008 Author Share Posted September 26, 2008 sorry i should have explained that this is a string on a page, its not a link and I am not submitting to the server. Link to comment https://forums.phpfreaks.com/topic/125885-solved-how-to-extract-numbers-out-of-a-string/#findComment-650935 Share on other sites More sharing options...
discomatt Posted September 26, 2008 Share Posted September 26, 2008 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> Link to comment https://forums.phpfreaks.com/topic/125885-solved-how-to-extract-numbers-out-of-a-string/#findComment-650941 Share on other sites More sharing options...
ballhogjoni Posted September 26, 2008 Author Share Posted September 26, 2008 discomatt thats it!! Thanks Link to comment https://forums.phpfreaks.com/topic/125885-solved-how-to-extract-numbers-out-of-a-string/#findComment-650945 Share on other sites More sharing options...
redarrow Posted September 26, 2008 Share Posted September 26, 2008 <?php $url="https://www.xxxxxxxx.com/partners/links/cardholders/details.asp?idmin=45621&tempid=568261"; $a=substr($url,70,-14); echo $a; ?> Link to comment https://forums.phpfreaks.com/topic/125885-solved-how-to-extract-numbers-out-of-a-string/#findComment-650948 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.