0

I have following html (html may be vary) in php variable. I have used append function (jQuery) for adding this html but always fail...... (due to not properly formated html). I've tried htmlentities,html_entity_decode and htmlspecialchars function for formating html but not success.... :( Any-buddy know how to escaped this html. (either by PHP or jquery and how???? appreciate for your answer)

<tr>
    <td class='paramlist_key'>
        <label id='ID' for='FOR' class='CLASS'>*AT</label>
    </td>
    <td class='CLASS_A'>
        <select id="19" name="Name" class="cc" title="" style="" size="">
            <option value="" >Select below</option>
            <option value="A" selected="selected">A</option>
            <option value="B">B</option>
        </select>
        <span id="mm" style="display:none;">&nbsp;</span>
    </td>
</tr>
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
Manish Trivedi
  • 3,481
  • 5
  • 23
  • 29

3 Answers3

2

Javascript code execution may be broken because of next line. Try this:

$('elementIdentification').before("< ?php echo str_replace('\r\n','',str_replace('\n','',$html)); ?>"); 
Rafay
  • 30,950
  • 5
  • 68
  • 101
VibhaJ
  • 2,256
  • 19
  • 31
0

You may not require jQuery Append to do this, if the HTML is decoded, you may simply echo it.

SHAKIR SHABBIR
  • 1,295
  • 1
  • 14
  • 25
0

You need to convert the HTML to a valid JavaScript string, which means it has to be 1 line and all "-quotes or '-quotes must be escaped, depending on which your outer style will be in the final JS. So something like:

$html = str_replace("\n", "\\n", $html);
$html = str_replace('"', '\"', $html);

Or even easier, just json_encode() it and omit the quotes in the JS script itself as json_encode() will add those.

Tino Didriksen
  • 2,215
  • 18
  • 21