简体   繁体   English

如何正确地将此PHP echo语句与字符串和函数连接在一起?

[英]How do I properly concatenate this PHP echo statement with a string and a function?

//top of the code just consists of an if statement and some code.
case 'itemimage' :

        echo '<div class="product-preview-image" style="background: red; height:75px; width:75px;"><img href=' . <?php grab_item_image(); ?> . "</div>"';
break;
    }
}

That was my attempt but it does not look rite on my text editor. 那是我的尝试,但在我的文本编辑器上看起来并不礼貌。 I am also using inline-css not sure if that matters. 我也使用inline-css不确定是否重要。

The only thing that i'm trying to echo out is this div with the function providing an href. 我要回声的唯一一件事是该div具有提供href的功能。

<div class="product-preview-image" style="background: red; height:75px; width:75px;"><img href="#thephpfunctionhere"</div>

It's kind of confusing me with all the single and double quotes. 这使我对所有单引号和双引号感到困惑。

Quotes Problem and you started <?php again. 报价问题,您再次启动<?php Use the code below 使用下面的代码

//top of the code just consists of an if statement and some code.
case 'itemimage' :

        echo '<div class="product-preview-image" style="background: red; height:75px; width:75px;"><img src="' .  grab_item_image() . '" /></div>"';
break;
    }
}

Hope this helps you 希望这对您有帮助

echo '<div class="product-preview-image" style="background: red; height:75px; width:75px;"><img src="' . <?php grab_item_image(); ?> . '"></div>"';

The image needs the ''SRC'' attribute instead of href. 图片需要“ SRC”属性,而不是href。 Also, since you are echo-ing within a php-tag you don't have to open the <\\?php again but directly refer to the function. 另外,由于您在php标签内回显,因此不必再次打开<\\?php,而是直接引用该函数。

echo 
    '<div class="product-preview-image" style="background: red; height:75px; width:75px;">' ,
        '<img src="' .  grab_item_image() . '" />' ,
    '</div>"';

Komma's are even faster when using a direct echo. 使用直接回声时,Komma的速度甚至更快。 Not suitable for assigning it to a $variable 不适合将其分配给$ variable

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM