将HTML解析为PHP

I hope you can help me with the following, i have a php method to scan a directory with pictures:

<?php
                        $dirname = "images/";
                        $images = scandir($dirname);
                        $ignore = Array(".", "..");
                        foreach($images as $curimg){
                            if(!in_array($curimg, $ignore)) {

                            echo "<li><a href=\"$dirname$curimg\"> class=\"portfolio-item-preview\" <img src=\"img/portfolio/portfolio-img-01.jpg\" /></a></li>
 ";

                            // echo "<li><a href=\"$dirname$curimg\"><img src=\"img.php?src=$dirname$curimg&w=300&zc=1\" alt='' /></a></li>
 ";
                                                }
                        }               
                    ?>

I want to put the following code after the foreach loop:

                            <li class="one-fourth logos">
                        <p>
                            <a href="images/project2/IMG_0268.jpg" class="portfolio-item-preview" data-rel="prettyPhoto"><img src="img/portfolio/portfolio-img-01.jpg" alt=" " width="210" height="145" class="portfolio-img pretty-box"/></a>
                        </p>
                        </li>

If I echo all the lines PHP generates all kinds of errors, could please someone help me with parsing the lines? I am just a beginner, sorry if it's very nooby:) I want this to create a class one-fourth logos for as long the folder contains images.

Just end your php code, put the HTML and reopen php.
Like that:

?>
    <li class="one-fourth logos">
                    <p>
                        <a href="images/project2/IMG_0268.jpg" class="portfolio-item-preview" data-rel="prettyPhoto"><img src="img/portfolio/portfolio-img-01.jpg" alt=" " width="210" height="145" class="portfolio-img pretty-box"/></a>
                    </p>
                    </li>
<?php

Because your HTML doesn't contain single quotation marks (') you can put them around your HTML and it will be a valid string which you can echo:

echo '<li class="one-fourth logos">
    <p>
        <a href="images/project2/IMG_0268.jpg" class="portfolio-item-preview" data-rel="prettyPhoto">
        <img src="img/portfolio/portfolio-img-01.jpg" alt=" " width="210" height="145" class="portfolio-img pretty-box">
        </a>
    </p>
</li>';