Php 在<;中使用变量;img可控硅=

Php 在<;中使用变量;img可控硅=,php,woocommerce,Php,Woocommerce,我有以下代码: //This one gets the image from the first product in the product category category: $catimg = get_the_post_thumbnail( $product->id, 'thumbnail' ); //This code contains custom text that also reads info from various variables, including the

我有以下代码:

//This one gets the image from the first product in the product category category:

$catimg = get_the_post_thumbnail( $product->id, 'thumbnail' );

//This code contains custom text that also reads info from various variables, including the `$catimg` variable:

$cat_art1 =  '<h1>'.$variable1.' This is some text that will be outputted to my site.</h1>
Here i want to screen the image <img src="' . $catimg . '" alt="alt">
Some more text and another '.$variable.' to end the line';
//此图像来自产品类别中的第一个产品:

$catimg=获取“发布”缩略图($product->id,“缩略图”); //此代码包含自定义文本,该文本还从各种变量读取信息,包括“$catimg”变量: $cat_art1='.$variable1.'这是一些将输出到我的站点的文本。 在这里,我想筛选图像 更多文本和另一个“$variable.”结束行“;
我尝试过许多谷歌搜索的各种解决方案,但没有一个适合我,因为它们都输出html标签。我的输出如下所示:

这有可能实现吗

谢谢

正如它在doc-it-return标签中所说的,不是url。 要获取url,请执行以下操作

$image_url = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'thumbnail' );

有关更多信息,请转到文档;)

我认为您的
$catimg
没有返回任何内容或空白字符串
我在php中尝试过这段代码,它可以处理静态图像,因此字符串插值是正确的。请检查您的
$catimg
变量

<?php
//This one gets the image from the first product in the product category category:

$catimg = 'https://pbs.twimg.com/profile_images/718314968102367232/ypY1GPCQ_400x400.jpg';
$variable1 = "Rajesh";
$variable = "Text";
//This code contains custom text that also reads info from various variables, including the `$catimg` variable:

$cat_art1 =  '<h1>'.$variable1.' This is some text that will be outputted to my site.</h1>
Here i want to screen the image <img src="' . $catimg . '" alt="alt">
Some more text and another '.$variable.' to end the line';
echo $cat_art1;
?>

wp_get_attachment_image_src(int$attachment_id,string | array$size='thumbnail',bool$icon=false)
//这张图片来自产品类别中的第一个产品:
$catimg=wp\u获取附件\u图像\u src(获取发布缩略图($product->id,'thumbnail');
//此代码包含自定义文本,该文本还从各种变量读取信息,包括“$catimg”变量:
$cat_art1='.$variable1.'这是一些将输出到我的站点的文本。
在这里,我想筛选图像
更多文本和另一个“$variable.”结束行“;

$catimg
中有什么?正如
获取帖子缩略图()的手册所说()“返回:(字符串)帖子缩略图图像标签。”。它返回一个img标记,而不仅仅是URL。您的代码在img-tag中添加了一个img标记作为源。有人告诉我$catimg包含一个>字符,告诉图像标记它到此结束,从而将alt=alt打印到浏览器中。正如@SougataBose所说,你能呼应出你的$catimg并告诉我们变量里面是什么吗?啊,忽略我的最后一个,我不知道它是wordpress。将$cat_art1更改为:'.$variable1'。这是一些将输出到我的网站的文本。在这里,我想屏幕上的图像'$卡蒂姆。”更多文本和另一个“$variable.”结束行“$catimg=获取“发布”缩略图($product->id,“缩略图”);你得到的网址是什么
 wp_get_attachment_image_src( int $attachment_id, string|array $size = 'thumbnail', bool $icon = false )


//This one gets the image from the first product in the product category category:

$catimg = wp_get_attachment_image_src(get_the_post_thumbnail( $product->id, 'thumbnail' ));

//This code contains custom text that also reads info from various variables, including the `$catimg` variable:

$cat_art1 =  '<h1>'.$variable1.' This is some text that will be outputted to my site.</h1>
Here i want to screen the image <img src="' . $catimg . '" alt="alt">
Some more text and another '.$variable.' to end the line';