在单引号字符串中包含变量的语法

Sorry for the trivial post, but I cannot figure this out on my own.

So I am basically appending a div and I need the maximum-length class to have a PHP variable like maximum-length-$max but I cannot figure out the syntax I need to use.

I have tried what is done before: '.$max.' ,but this does not work.

$addressFields .= '<div style="position: relative"><input type="text" title="'.$this->__('Street Address '.($_i+1)).'" name="billing[street]['.$_i.']" id="billing:street'.($_i+1).'" value="'.$dataHelper->clearDash($this->getQuote()->getBillingAddress()->getStreet($_i+1)).'" class="'.(($_i == 0)? 'required-entry ' : ''). 'input-text validate-address-lenght maximum-length-$max />';

Try to close ' before and after you varable. Try following code:

$addressFields .= '<div style="position: relative"><input type="text" title="'.$this->__('Street Address '.($_i+1)).'" name="billing[street]['.$_i.']" id="billing:street'.($_i+1).'" value="'.$dataHelper->clearDash($this->getQuote()->getBillingAddress()->getStreet($_i+1)).'" class="'.(($_i == 0)? 'required-entry ' : ''). 'input-text validate-address-lenght maximum-length-'.$max.'" />';

That is one terrible one-liner to read.

I would do the following using sprintf:

    $addressFields .= sprintf('
        <div style="position: relative">
            <input type="text"
                    title=%s
                    name="billing[street][%s]"
                    id="billing:street%s"
                    value="%s"
                    class="%s input-text validate-address-lenght maximum-length-%s"
             />',
        $title = $this->__('Street Address ' . ($_i + 1)),
        $name = $_i,
        $id = $_i + 1,
        $value = $dataHelper->clearDash($this->getQuote()->getBillingAddress()->getStreet($_i + 1)),
        $class = ($_i === 0) ? 'required-entry ' : '',
        $max = 'YOUR_MAX_VALUE_HERE'
    );

Also shouldn't "validate-address-lenght" be "validate-address-length" in your class values?