Hybride Posted August 17, 2007 Share Posted August 17, 2007 http://vtest.anekyu.com/test.php Basically what am trying to do is get the integer off of that page (it's currently at 28,228,474). I managed to cut off the front (so it starts with the integer), but I can't figure the combination to make it end with the integer. Any ideas? Thanks! <? $var = "metallica"; $url = file_get_contents("http://www.last.fm/music/" . $var); $v1 = 'read more'; $pos = strpos($url, $v1); $v2 = 'plays scrobbled'; $pos2 = strpos($url, $v2); /* if ($pos2 === false) { echo 'String does not exist'; } else { echo "'$v1' exists at: $pos "; } */ $test = substr($url, $pos, $pos2); $test2 = substr($test, 10); ?> Quote Link to comment https://forums.phpfreaks.com/topic/65335-solved-silly-substr-problem/ Share on other sites More sharing options...
Fadion Posted August 17, 2007 Share Posted August 17, 2007 I quickly tried this localy so it should work <?php $var = "metallica"; $url = file_get_contents("http://www.last.fm/music/" . $var); $pos1 = strpos($url, "<h5 class=\"subhead\">"); $len1 = strlen("<h5 class=\"subhead\">"); $url1 = substr($url, $pos1+$len1); $pos2 = strpos($url1, " plays scrobbled on Last.fm</h5>"); $url2 = substr($url1, $pos2); $urlFinal = str_replace($url2, '', $url1); echo $urlFinal; ?> Im sure there's a simpler and quicker technique for doing that, then just manipulating strings several times in a row, which adding the remote file make the proccess a lot slow. Quote Link to comment https://forums.phpfreaks.com/topic/65335-solved-silly-substr-problem/#findComment-326368 Share on other sites More sharing options...
btherl Posted August 17, 2007 Share Posted August 17, 2007 A quicker approach may be to use file() to read the page into an array of lines, find the line containing "scrobbled" and process only that line. Quote Link to comment https://forums.phpfreaks.com/topic/65335-solved-silly-substr-problem/#findComment-326373 Share on other sites More sharing options...
Hybride Posted August 17, 2007 Author Share Posted August 17, 2007 I love you guys, thanks for your help! Both worked Quote Link to comment https://forums.phpfreaks.com/topic/65335-solved-silly-substr-problem/#findComment-326378 Share on other sites More sharing options...
MadTechie Posted August 17, 2007 Share Posted August 17, 2007 simple one <?php $var = "metallica"; $data = file_get_contents("http://www.last.fm/music/" . $var); if (preg_match('/<h5 class="subhead">([0-9,]*) plays scrobbled/im', $data, $regs)) { $result = $regs[1]; } echo $result; ?> Quote Link to comment https://forums.phpfreaks.com/topic/65335-solved-silly-substr-problem/#findComment-326381 Share on other sites More sharing options...
Hybride Posted August 17, 2007 Author Share Posted August 17, 2007 Wow, that worked, too! Thanks so much for all your help! Quote Link to comment https://forums.phpfreaks.com/topic/65335-solved-silly-substr-problem/#findComment-326383 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.