doucheng9634
2011-11-02 05:58 阅读 18
已采纳

如何使用href调用php中的图像?

I have a bit of code that, using php, I want it to call in an image rather than what it is currently calling in (which is 'echo bloginfo('name');). However, I am sadly PHP illiterate and have no idea how to do this with the 'a href' posted below. Could anyone help me call to /images/logo.png? Many thanks in advance!

<h1><a href="<?php echo get_settings('home'); ?>"><?php echo bloginfo('name'); ?></a></h1>
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

3条回答 默认 最新

  • 已采纳
    douwen3362 douwen3362 2011-11-02 06:05

    The tag for add images is <img src=""> on the srcattribute you need to write the url of the image you want (in your case /images/logo.png) so, replacing the code you pasted

    <h1><a href="<?php echo get_settings('home'); ?>"><img src="/images/logo.png"></a></h1>
    

    Take into account that the path to the image you are using now is a relative one (relative to the document requiring the image) so you probably want to have the absolute url instead.

    点赞 评论 复制链接分享
  • doutang0335 doutang0335 2011-11-02 06:07

    What is the return of get_settings() function? ==> name's Image?
    I think this code is OK, but you should check the return value of your function.

    点赞 评论 复制链接分享
  • douzhaishan5462 douzhaishan5462 2011-11-02 06:08

    ...place at the beginning of you webpage, near the top with the rest of your PHP/JavaScript:

        <?php
    
        $image_name = '/images/logo.png';
    
        ?>
    

    ...In this are you place allof your HTML...

        <img src='<?php echo $image_name; ?>'>
    

    Basically, you can have a variable named 'image_name' that you can have be anything.

    If you wanted the HREF link area to be a variable that could be changed as well, just do this:

        <?php
    
        $image_name = '/images/logo.png';
        $image_url = 'http://www.google.com';
    
        ?>
    

    Then...

        <a href='<?php echo $image_url; ?>' border='0'><img src='<?php echo $image_name; ?>'></a>
    
    点赞 评论 复制链接分享

相关推荐