php修剪空间后的一切

时间:2012-12-20 10:48:02

标签: php string variables string-concatenation

我真的在挠头......

我正在尝试在输入和textarea字段中添加一个类,但每当我这样做时:

$inputclass = $class." multilanginput"; 

第二部分没有附加,但当我遗漏空间并按照这样做时:

$inputclass = $class."multilanginput"; 

它运作得很好......

我之前从未遇到过这个问题,任何想法出了什么问题?

这是这个小功能的一部分:

function backend_dynamic_dialoginput($label,$class,$type = 'single',$lang = "none"){


if($lang == "none"){
    $lang = "";
}
else{
    $lang = "_".$lang;
}

$class = $class.$lang;
$id = "";

if($type == "singleint" || $type == "multiint"){
    $id = $class."_m";
    $inputclass = $class." multilanginput";
}else{
    $inputclass = $class;  
}


$html = "
<div style='padding-left:10px;margin-top:1px;background-color:#dddddd;padding-bottom:8px;padding-top:8px;'>
    <div style='float:left;font-size:13px;color:#5a5a5a;padding-top:6px;margin-bottom:2px;width:30%;text-align:right;padding-right:4px;' class='font_lato'>".$label."</div>
    ";

    if($type == "single" || $type == "singleint"){
        $html .= "<input type='text' value=".$inputclass." style='font-size:12px;width:60%;border:1px solid #ffffff;padding:2px;background-color:#dddddd;' class='font_din' id='".$id."' class='".$inputclass."'>";
    }
    else if($type == "multi" || $type == "multiint"){
        $html .= "<textarea style='font-size:12px;width:60%;border:1px solid #ffffff;padding:2px;background-color:#dddddd;' class='font_din' id='".$id."' class='".$inputclass."' rows=2></textarea>";
    }

    $html .= "
    ";

    if($type == "singleint" || $type == "multiint"){
    $html .= "<div style='float:right;font-size:12px;background-color:#eeeeee;margin-right:4px;' id='".$class."' class='togglefullscr font_lato'>Int.</div>";
    }


    $html .= "
    </div>";

if($type == "singleint" || $type == "multiint"){
$html .= backend_dynamic_internationaldialog($label,$class,$type);   
}

return $html;

}

3 个答案:

答案 0 :(得分:1)

你的引号错了:

$html .= "<input type='text' value=".$inputclass."

必须是$html .= "<input type='text' value='".$inputclass."'$html .= "<input type='text' value=\"".$inputclass."\"

但是,我强烈建议对字符串使用单引号:

$html .= '<input type="text" value="'.$inputclass.'"...>';

答案 1 :(得分:1)

您没有在HTML属性周围添加引号。

将行更改为:

$html .= "<input type='text' value='".$inputclass."' style='font-size:12px;width:60%;border:1px solid #ffffff;padding:2px;background-color:#dddddd;' class='font_din' id='".$id."' class='".$inputclass."'>";

当你省略这样的引号时,第二个类名将被视为另一个属性。

如果validate your markup; - )

,可以轻松避免这样的问题

答案 2 :(得分:0)

您可以使用php中的\x20\040来转义空格。

http://php.net/manual/en/regexp.reference.escape.php

请参阅手册

相关问题