Q:

Nested quotation paradox PHP

I'm having a problem regarding nested quotations... more like a paradox actually. 
So this is the piece of code in which i use 4 levels of nestes quotations, and somehow (for what I can see in Chrome's Developer's Tools) the browser interprets incorrectly the third and fourth level:
    echo
    "<script type='text/javascript'>
    var latlng = new L.LatLng(".$row ['lat'].", ".$row ['long']."); 
    var flyer = ";

    echo 
    "\"<img class='flyerwide' 
    src='http://plandenuit.com/boliches/flyers/".$clubday."/".$name.".jpg'/>
    <br /><br />";

    echo "<a href='#' onClick='return false' onmousedown=

1.3 In this line is the problem, I use ' as 3rd level quote and \' as fourth
    'javascript:swapContent(\'profilepage\',\'\',\'".$influenceGroupRow['id']."\');'>

1.3 End of the line of the problem
    <img class='pic' src='http://graph.facebook.com/".$influenceGroupRow['id']."/picture'/></a>";

    echo
    "\"; 
    var MyIcon = L.Icon.extend({
    iconUrl: 'boliches/icons/".$name.".png',
    shadowUrl: null,
    iconSize: new L.Point(50, 50),
    shadowSize: null,
    iconAnchor: new L.Point(25, 25),
    popupAnchor: new L.Point(1, 1)
    }); 
    var icon = new MyIcon();    
    var marker = new L.Marker(latlng, {icon: icon});
    map.addLayer(marker);   
    marker.bindPopup(flyer);
    map.panTo(new L.LatLng(".$setlat.", ".$setlong."));
    </script>
    ";

Now, I've tried almost everything that I could imagine or google. Chrome's Developer's Tools shows that the browser interpreted the line as follows:
    <a href="#" onclick="return false" onmousedown="javascript:swapContent(" profilepage','','1005497360');'="">

Can anyone crack this one? Im kind of an amateur here.
(Oh! by the way, this is all in a while loop so it must be echoed out)

A:

You can eliminate at least one level of quoting by using a HEREDOC:
echo <<<EOL
<script type="text/javascript">
    var latlng = new L.LatLng({$row ['lat']}, {$row['long']}); 
    var flyer = '<img class="flyerwide" src="http://plandenuit.com/boliches/flyers/{$clubday}/{$name}.jpg"/ ><br /><br />';
etc...
EOL;

