开发者

strange behaviour of str_replace in php

开发者_开发知识库
href=" <?php 
$zzz_stylesheet = "http://127.0.0.1/www/wordpress/wp-content/themes/mytheme/style.css"; 
echo str_replace(".css","-mytheme.css",$zzz_stylesheet);
?>

works but

href=" <?php 
$zzz_stylesheet = bloginfo('stylesheet_url'); 
echo str_replace(".css","-mytheme.css",$zzz_stylesheet);
?>

does not work. Why? bloginfo is a function in Wordpress which returns the value I have used in first code line.


From Wordpress’ documentation to bloginfo:

Displays information about your blog […] This always prints a result to the browser. If you need the values for use in PHP, use get_bloginfo().

(emphasis added)

So: Use get_bloginfo instead.


You have a space after the href="

Do you know about that. If you remove it, then your code, providing that bloginfo() works as expected should work.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜