amax,
I would recommend doing it this way..
If you have short-tags enabled in your PHP.INI you could do:
<?=$thumb1 ?>
Or alternatively you could echo the entire <img onclick=.... string
<?php
echo "<img onclick=\"javascript:switchImage('$thumb', '$thumb1Caption');" src="$thumb1\"/>";
?>
Just be 100% sure to escape (with a ) each 'Double Quote' used within the echo statement.
The method you are using is the one that I would prefer to use, however.