2015-11-05 88 views
0

我有此片段的代码,其抓住SVG图像的源,并将其添加到HTML:Add功能PHP的file_get_contents路径

<?php echo file_get_contents("assets/images/lightening.svg"); ?> 

我要添加的函数的根(); (我已经工作),它告诉它在哪里站点的根(它在多个位置提升网站)的开始路径。

我要的是这个版本的作品:

<?php echo file_get_contents("'root();'.assets/images/lightening.svg"); ?> 

任何帮助将大大赞赏。 谢谢。

+0

的file_get_contents(根()'资产/图像... – kainaw

回答

0

上依赖是否root()返回路径,而不尾随slath功能:

<?php echo file_get_contents(root() . "/assets/images/lightening.svg"); ?> 

或斜线:

<?php echo file_get_contents(root() . "assets/images/lightening.svg"); ?> 
+0

。非常感谢你!一直在学习:) – James

+0

当我的根有一个好的路径时,这很好,但是当根只是“/”时它失败并在图像之前打印出“/”,有什么想法? – James

+0

@詹姆斯,没有重构你的代码,你可以'echo file_get_contents((root()==='/'?'/':root())。“assets/images/lightening.svg”);'' –