Jump to content

[SOLVED] silly substr() problem


Hybride

Recommended Posts

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);
?>

Link to comment
https://forums.phpfreaks.com/topic/65335-solved-silly-substr-problem/
Share on other sites

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.

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.