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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.