Question

For example, I know you can go from " to ' but is there a third?

I am making a $form variable and I need 3 levels of quotes

    $form = "<table id ='create_school_table'>
                    <tr>
                        <td>school name:</td>
                        <td><input type = 'text' maxlength='50' name='school_name' style='width: 174px;'/></td>
                    </tr>
                    <tr>
                        <td>state:</td>
                        <td><select name='state'>
                            <?php foreach ($states as $state) : ?>
                               //THIS NEXT LINE IS TRIPPING ME UP
                                <option value='<?php echo $state['state_name']; ?>'>
                                    <?php echo $state['state_name']; ?>
                                </option>
                            <?php endforeach; ?>
                    </select></td>
                    </tr>
                    <tr>
                        <td></td>
                        <td><input type='button' value='add school' name='submitbtn' onclick='execute_add_school()' /></td> 
                    </tr>
                </table>"
Was it helpful?

Solution

Can you use more variables?

$form = "Your initial HTML";

$states = "";
foreach ($states as $state) {
    $states .= "<option value='" . $state['state_name'] . "'>" 
            . $state['state_name'] . "</option>";
}

$form .= $states;
$form .= "the rest of your HTML";

If you are explicitly trying to keep it all in one variable, feel free to update your question to reflect that.

OTHER TIPS

You can rewrite your code for clarity.

Assign blocks of html or processes results to variables and concatenate them wherever you need them.

It is not quite clear what you are doing.

To escape quotes, use \"
To escape escaped quotes, use \\\"
etc.

However, it seems to me that you want the current value of the variable. You cannot "echo" into a variable, "echo" is for output. See fettereddingoskidney's answer for that.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top