开发者

Php code to scrape the values from other site [closed]

开发者 https://www.devze.com 2023-03-31 23:49 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. 开发者_StackOverflow社区 Closed 11 years ago.

i am trying to get a some values from other site using code below

$values = file_get_contents('http://www.example.com/');

(MISSING CODE)

echo $values;

the site has only text all in first row. basically its just a text line. so i need to get 11th to 18th vale from it.

values are not in csv its values are in body tags and view source is {"token":"ABCDEFGH","expire":2345789542} so i need abcdefgh value


If your example is correct, it's a format called JSON. Php has support for it:

$decoded = json_decode('{"token":"ABCDEFGH","expire":2345789542}');
echo $decoded->token;

outputs

ABCDEFGH


Just try to use substring on the output value like the one i ve given below

substring($values,11,7);


Do you mean that the site is returning CSV (a line of comma or tab delimited text?) If so check out str_getcsv.

An example:

$text = file_get_contents('http://www.domain.com/');
$values = str_getcsv($text);
for ($i=11; $i <= 18; $i++) {print $values[$i]."\n";}
0

精彩评论

暂无评论...
验证码 换一张
取 消