![](/img/trans.png)
[英]Removing an <img> tag from string and placing it in variable where img src location in string can vary
[英]Removing The IMG SRC tag in Wordpress
我正在嘗試從php中刪除“ img src”標簽,因此它只會顯示圖像的url,而不是顯示實際的圖像。 這是到目前為止我得到的代碼,它可以完美地工作,但是在渲染時,它顯示的是縮略圖而不是URL。
<?php $pics = get_post_meta( $post->ID, 'pics', true );
foreach( $pics as $pics)
{
$image_attributes = wp_get_attachment_image_src( $pics['pictures'] );
echo '<img src="' . $image_attributes[0] . '" />';
}
?>
我知道有一種方法可以做到這一點,但是我不知道如何在不破壞圖像代碼的情況下刪除標簽。 任何幫助表示贊賞。
如果您只想echo
顯圖像src而不將其顯示為圖像,請更改
echo '<img src="' . $image_attributes[0] . '" />';
至
echo $image_attributes[0];
<?php
$pics = get_post_meta( $post->ID, 'pics', true );
foreach( $pics as $pics)
{
$image_attributes = wp_get_attachment_image_src( $pics['pictures'] );
echo $image_attributes[0];
}
?>
那么,您是否要在頁面上顯示帶有標簽和src屬性的“ html代碼”?
您是否嘗試將“ img”標簽包含在“ pre”標簽中?
echo '<pre><img src="' . $image_attributes[0] . '" /></pre>';
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.