2012-01-01 66 views
0

我发现了一个在浏览时旋转文本的函数。 当你的话,到了最后,输入以下行:从另一个文件中获取文本并将其包含到另一个函数中

echo spin('{This|Here} is {some|a little bit of} {example|sample} text.'); 

然后它会给你如。 “这是一个小范例测试。”

现在,我想从另一个文件中提取要旋转的文本,以便“{This | Here} {some | {} | {example | sample} text”。在例如。 spintext.php。我无法真正做到这一点。因为例如。以下(以及对此的不同变化)不起作用:

$text = include("/home/domainpath/public_html/files/spintext.php"); 
echo spin('.$text.'); 

希望有人能指出上面的错误。

+0

spintext.php里面有什么? – emaillenin 2012-01-01 17:13:04

+0

只是以下内容:{This | Here}是{some |一点点} {example | sample}文本。 – Steven 2012-01-01 17:26:43

回答

2

试试这个。

$text = file_get_contents("/home/domainpath/public_html/files/spintext.php"); 
echo spin($text); 
+0

不起作用。这将以字符串形式返回PHP代码。 – 2012-01-01 17:11:25

+0

@Cicada OP指出原始文本出现在PHP文件中。 – emaillenin 2012-01-01 17:12:48

+0

OP的帖子提示,spintext.php的内容是实际的文本,而不是PHP代码,尽管它的命名很糟糕。它不起作用的原因是''。$ text.''应该只是'$ text'。 – JJJ 2012-01-01 17:13:52

0

使用返回值的包含文件:

test.php的

$text = "blah blah blah...."; 
return $text; 

然后使用它是这样的:

$mytext = include 'test.php'; 

您可以访问http://php.net/manual/en/function.include.php。检查示例#5 include()和return()语句

+0

对不起,但这不是'包括'的作品。 – JJJ 2012-01-01 17:41:23

+0

如果它不以这种方式工作,那么只需访问我在答案中包含的链接和示例,以确保我错了。 – MahanGM 2012-01-01 19:27:06

相关问题