【问题标题】:Stripping out HTML characters to display image剥离 HTML 字符以显示图像
【发布时间】:2014-02-22 21:17:45
【问题描述】:

我正在尝试显示来自 Joomla 3.2 的介绍图像,它保存在表中“图像”列中的数据库中。但是,介绍图像和全文图像保存在同一列中,因此当我尝试回显该列时,我只是获取值。

我看到了这个值:

<?php echo $item->images; ?>

这是输出以下内容:

{"image_intro":"images/stories/imagetest.jpg","float_intro":"","image_intro_alt":"","image_intro_caption":"","image_fulltext":"","float_fulltext": "","image_fulltext_alt":"","image_fulltext_caption":""}

不过,理想情况下,我希望能够剥离 html 并仅显示“image_intro”的值,然后我可以将其用于 img src。以上似乎是 JSON 格式,但我不知道如何回显第一个值。

【问题讨论】:

    标签: php joomla json joomla3.2


    【解决方案1】:

    试试这个:

    $decodedJsonString = json_decode('{"image_intro":"images/stories/Catcchampcocktails (2).jpg","float_intro":"","image_intro_alt":"","image_intro_caption":"","image_fulltext":"","float_fulltext":"","image_fulltext_alt":"","image_fulltext_caption":""}');
    
    echo $decodedJsonString->image_intro;
    

    【讨论】:

    • 感谢您的回复。我刚刚尝试了以下方法,它奏效了:&lt;?php $images = json_decode($item-&gt;images);?&gt; 然后&lt;?php $jsonString = json_decode($item-&gt;images); ?&gt; &lt;img src="&lt;?php echo $jsonString-&gt;image_intro;?&gt;" alt="&lt;?php echo $item-&gt;title; ?&gt;" /&gt; 效果很好!
    • 太棒了!请务必参阅此文档以查看您可以访问的所有字段:tables/content。您说 Joomla 将图像数据存储在数据库中的 JSON 字符串中是正确的
    猜你喜欢
    • 2012-05-28
    • 2012-09-30
    • 1970-01-01
    • 2011-05-02
    • 1970-01-01
    • 1970-01-01
    • 2012-11-15
    • 1970-01-01
    相关资源
    最近更新 更多