0

我想将网站的内容视为字符串,并分配给变量。

但是,如果我写<?php $stringvariable = ' include https://api.twitter.com/1/statuses/user_timeline/USER.rss ' ?>

php 将假定包含函数和其中包含的地址只是一个字符串。

有什么办法可以避免这种情况吗?

PS 我可能实际上会将该功能read_file用作基本安全措施,以防万一我正在阅读的 RSS 提要被黑客入侵。

4

2 回答 2

3
$variable = file_get_contents(URL)
于 2012-11-05T14:56:22.790 回答
2

试试这个

$stringvariable = file_get_contents('https://api.twitter.com/1/statuses/user_timeline/USER.rss');

请勿INCLUDE用于此目的!

请注意

包含不是一个函数 - 它是控制结构! http://php.net/manual/en/function.include.php

于 2012-11-05T14:56:37.440 回答