【问题标题】:set value's in img tag in php在 php 中的 img 标签中设置值
【发布时间】:2014-01-13 11:42:25
【问题描述】:

我正在尝试使用 php 分配图像的动态路径。

在尝试使用

回显路径时
echo '<img src="'.$guild_image_path.'"/>';

我得到了正确的路径。

但如果我在我的应用程序中应用相同的内容,我将无法获得图像路径。

请参考下面我的代码,

printf( '<span class="byline"><span class="rounded_image"><a  href="%4$s" rel="author"><?php echo '<img src="'.$guild_image_path.'"/>'; ?>%5$s</a></span></span>',  
                esc_url( get_permalink() ),
        esc_attr( get_the_date( 'c' ) ),
        esc_html( get_the_date() ),
        esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
        get_the_author()
    );

请帮我做这件事。

【问题讨论】:

    标签: php image kohana kohana-3


    【解决方案1】:

    为什么在 printf 中使用 echo? 第二个 printf 是 arleady PHP,所以你不需要再次打开 php 标签。

    printf( '<span class="byline"><span class="rounded_image"><a  href="%4$s" rel="author"><img src="'.$guild_image_path.'"/>%5$s</a></span></span>',  
                esc_url( get_permalink() ),
        esc_attr( get_the_date( 'c' ) ),
        esc_html( get_the_date() ),
        esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
        get_the_author()
    );
    

    阅读有关 printf 的更多信息:http://www.php.net/manual/ru/function.printf.php

    【讨论】:

      【解决方案2】:

      尝试在printf() 之前使用error_log 或echo 进行调试,以确保您获得变量$guild_image_path 中的值。

      error_log('image path'.$guild_image_path);
      

      echo $guild_image_path;
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-12-29
        • 1970-01-01
        • 2019-02-10
        • 1970-01-01
        • 1970-01-01
        • 2018-02-03
        • 2021-05-20
        • 2021-10-27
        相关资源
        最近更新 更多