Mário Correia Mário Correia - 2 years ago 86
PHP Question

PHP echo problems

Hello i have one funcion and my echo is:

echo '<tr>
<td align="center" style="padding:5px;"><img src="/chat/emotes/illuminati.png" onclick="insertSmiley("hallo")"> <br>:illuminati:</td>

the problem is that onclick="insertSmiley("hallo")" must be with ' and not with " if i put this in html everything works.
but in php echo when i click nothing append

my index.php have this script in body

<script type="text/javascript">
function insertSmiley(smiley)

var currentText = document.getElementById("send");

var smileyWithPadding = " " + smiley + " ";
currentText.value += smileyWithPadding;


and the other code is in my chat.php

echo '<textarea id="send" maxlength="125" rows="2" placeholder="Enter your message"></textarea>
<td align="center" style="padding:5px;"><img src="/chat/emotes/smile.png" onclick="insertSmiley("hallo")"> <br>:illuminati:</td>

i really think that the problem is because i cant use '' in echo and i need it for onClick...('hallo')

Answer Source

use \' to just print '

Backslashes are used in PHP to escape special characters within quotes. As PHP does not distinguish between strings and characters

If your write like this

echo 'check it \' out'; 

it will give output like this

check it ' out

So use like this

echo '<tr>
<td align="center" style="padding:5px;"><img src="/chat/emotes/smile.png" onclick="insertSmiley(\'hallo\')"> <br>:illuminati:</td>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download