【问题标题】:Specify width and height of an image in php在php中指定图像的宽度和高度
【发布时间】:2016-03-30 06:23:20
【问题描述】:

我在 PHP 中创建了一个变量来存储 HTML 代码:

$success = (
"<p>Result:</p><br>
<table style='margin-bottom:0; color:#000;'>
    <tr>
        <td>Option1:</td>
        <td>
        <img src='block.gif'
        width= ".(100*round($option1/($option1+$option2+$option3),2)).
        "height='20px'>".
        (100*round($option1/($option1+$option2+$option3),2))." %" ."
        </td>
    </tr>

    <tr>
        <td>Option2:</td>
        <td>
        <img src='block.gif'
        width= ".(100*round($option2/($option1+$option2+$option3),2)).
        "height='20px'>".
        (100*round($option2/($option1+$option2+$option3),2))." %" ."
        </td>
    </tr>

    <tr>
        <td>Option3:</td>
        <td>
        <img src='block.gif'
        width= ".(100*round($option3/($option1+$option2+$option3),2)).
        "height='20px'>".
        (100*round($option3/($option1+$option2+$option3),2))." %" ."
        </td>
    </tr>

此代码显示为民意调查的结果,到目前为止似乎可以正常工作。 'block.gif' 的宽度等于它的相应值。我的问题是,由于某种原因,高度也以相同的方式呈现,尽管我将其值设置为 20px。

我认为错误存在于语法中的某个地方,但我找不到它。

【问题讨论】:

  • 嗯...尝试不使用% 单元。让数字为px 或无单位。
  • 检查 html,你缺少的单位和引号

标签: php html css image


【解决方案1】:

这是你的代码,

width= ".(100*round($option1/($option1+$option2+$option3),2)).
    "height='20px'>".

如果那个大表达式的值为10,它会创建,

width= 10height='20px'>

这就是问题所在。正确的形式是,

width='10px' height='20px'>

因此您需要相应地更改代码。只需移动空格并添加两个单引号即可。

width='".(100*round($option1/($option1+$option2+$option3),2)).
    "px' height='20px'>".

【讨论】:

  • 就是这样,太棒了!非常感谢你的帮助,你让我很开心:)
猜你喜欢
  • 1970-01-01
  • 2016-04-08
  • 2010-11-19
  • 2011-11-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-06-06
  • 2012-12-11
相关资源
最近更新 更多