Onclick Word Replacement not working correctly with PHP : <p>I have this code:</p>

<p><code>&lt;a class='show' data-id='".$random."' href='javascript:void(0)' onclick='if(this.innerHTML == 'Click Here to Read More'){this.innerHTML = 'Click Here to Read Less'}else{this.innerHTML = 'Click Here to Read More'}'&gt;Click Here to Read More&lt;/a&gt;</code></p>

<p>When the page is returned though everything is returned weird and items are missing in source code like so:</p>

<pre><code>&lt;a class="show" onclick="if(this.innerHTML == " href="javascript:void(0)" data-id="23272317" }'="" }else{this.innerhtml="Click Here to Read More" more'){this.innerhtml="Click Here to Read Less" read="" to="" here="" click=""&gt;Click Here to Read More&lt;/a&gt;
</code></pre>

<p>Im sure its as simple as a quotes issue but im stuck. Anyone able to point me in the right direction or explain how or why this happens with only javascript?</p>
