我有一个PHP的回声,我想用一个变量width属性来避免需要一个if语句。 我试图用这个代码:
<?php echo variable; ?>
它没有工作。
这里是我的代码:
echo "<div class='progress-bar progress-bar-success' role='progressbar' aria-valuenow='25' aria-valuemin='0' aria-valuemax='100' style='width: (Variable)'>";
这是否工作:
echo "<div class='progress-bar progress-bar-success' role='progressbar' aria-valuenow='25' aria-valuemin='0' aria-valuemax='100' style='width: ".$variable."'>";
不回应的HTML只能随声附和变量:
<div class='progress-bar progress-bar-success' role='progressbar' aria-valuenow='25' aria-valuemin='0' aria-valuemax='100' style='width: <?php echo $variable?>px'>;
请注意,我也呼应了可变后添加像素。
<?php $variable=100'; ?>
echo "<div class='progress-bar progress-bar-success' role='progressbar' aria-valuenow='25' aria-valuemin='0' aria-valuemax='100' style='width: ( ".$variable.")'>";
如果你想成为更看中你可以检查变量不为空:
<?php if($variable != ""):?>
<!-- this will be the output if variable has some value -->
<div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100" style="width:<?php echo $variable; ?>px">
<?php else: ?>
<!-- some default value -->
<div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100" style="width:100px">
<?php endif;?>
尝试:
$variable = "10px";
echo "<div class='progress-bar progress-bar-success' role='progressbar' aria-valuenow='25' aria-valuemin='0' aria-valuemax='100' style='width: $variable'>";
当您使用“-string工程