Search code examples
phpapostrophe

displaying text with apostrophe


I have this code

echo "<img src='".MY_URL."/uploads/avatars/blank.gif' class='img-circle' title='$name' border='0' alt='".$name."' height='48' width='48'>";

How do i display this properly if $name is Abbas Sa'ad

It always echo Abbas Sa only


Solution

  • You have to use htmlspecialchars() with ENT_QUOTES like below:-

    echo "<img src='".MY_URL."/uploads/avatars/blank.gif' class='img-circle' title='". htmlspecialchars($name, ENT_QUOTES) ."' border='0' alt='". htmlspecialchars($name, ENT_QUOTES) ."' height='48' width='48'>";