DOMDocument搜索文件中的字符串并删除包含列表项的php

DOMDocument搜索文件中的字符串并删除包含列表项的php,php,slideshow,domdocument,removechild,Php,Slideshow,Domdocument,Removechild,我正在创建一个幻灯片编辑器。“删除幻灯片”功能有问题。我基本上必须在外部文件中搜索包含图像路径的。这是到目前为止我已经得到的代码,但我不知道如何编写“在列表项中搜索图像路径”行(我目前有stristr)。以下是我所拥有的: <?php $image = $_GET['image']; $file = $_GET['file']; $path = '../../yardworks/content_pages/' . $file; $orImage =

我正在创建一个幻灯片编辑器。“删除幻灯片”功能有问题。我基本上必须在外部文件中搜索包含图像路径的
  • 。这是到目前为止我已经得到的代码,但我不知道如何编写“在列表项中搜索图像路径”行(我目前有stristr)。以下是我所拥有的:

        <?php
        $image = $_GET['image'];
        $file = $_GET['file'];
        $path = '../../yardworks/content_pages/' . $file;
        $orImage = substr($image, 39);
    
        /* Create string of contents */
        $mydoc = new DOMDocument('1.0', 'UTF-8');
        $mydoc->loadHTMLFile($path);
        foreach ($mydoc->getElementsByTagName("img") as $listItems){
            $images = $listItems->getAttribute("src");
            if ((stristr($images, $image) !== FALSE) || (stristr($images, $orImage) !== FALSE)){
                foreach ($mydoc->getElementsByTagName("li") as $delete){
                    if ($x == $y){
                        $mydoc->removeChild($delete);
                        $mydoc->saveHTMLFile($path);
                        $file = file_get_contents($path);
                        $file = str_replace("&lt;", "<", $file);
                        $file = str_replace("&gt;", ">", $file);
                        file_put_contents($path, $file);
                        ?>
                        <!-- Confirmation and redirect -->
                        <script>
                            window.alert("Slide has been deleted.");
                            window.location.replace("slideshows.php");
                        </script>
                        <noscript>
                            Slide has been saved.<br />
                            <a href="slideshows.php">&laquo; Return to Select a Slideshow</a><br />
                        </noscript>
                        <?php
                    }
                    else $y++;
                }
            }
            $x++;
        }
        ?>
        <script>
            window.alert("Slide was not found.");
            window.location.replace("slideshows.php");
        </script>
        <noscript>
            Slide has been saved.<br />
            <a href="slideshows.php">&laquo; Return to Select a Slideshow</a><br />
        </noscript>
    
    
    window.alert(“幻灯片已被删除”);
    window.location.replace(“slideshows.php”);
    幻灯片已保存。

    window.alert(“未找到幻灯片”); window.location.replace(“slideshows.php”); 幻灯片已保存。

    我不知道,但可能是
  • 复制不正确?以下是我试图访问的文件:

       <center><h1>1 Car 1 Story Garages</h1></center>
    <div id="gallery" class="content mceNonEditable">
        <div id="controls" class="controls mceNonEditable"></div>
        <div class="slideshow-container mceNonEditable">
            <div id="loading" class="loader mceNonEditable"></div>
            <div id="slideshow" class="slideshow mceNonEditable"></div>
        </div>
        <div id="caption" class="caption-container"></div>
    </div>
    <div id="thumbs" class="navigation">
    
    <ul class="thumbs noscript" id="replace">
        <li>
            <a class="thumb" href="images/garages/1car1story1.png">
                <img src="images/garages/1car1story1.png" alt="1 Car 1 Story Garage 1" height="100px" width="130px" class="slideshow-img" />
            </a>
            <div class="caption">
                <div class="image-title">1 Car 1 Story Garage 1</div>
                <div class="image-desc">12x24 Vinyl A-Frame with optional cupola</div>
            </div>
        </li>
    
        <li>
            <a class="thumb" href="images/garages/1car1story2.png">
                <img src="images/garages/1car1story2.png" alt="1 Car 1 Story Garage 2" height="100px" width="130px" class="slideshow-img" />
            </a>
            <div class="caption">
                <div class="image-title">1 Car 1 Story Garage 2</div>
                <div class="image-desc">12x24 Duratemp A-Frame w/ optional Stockton glass</div>
            </div>
        </li>
    
        <li>
            <a class="thumb" href="images/garages/1car1story3.png">
                <img src="images/garages/1car1story3.png" alt="1 Car 1 Story Garage 3" height="100px" width="130px" class="slideshow-img" />
            </a>
            <div class="caption">
                <div class="image-title">1 Car 1 Story Garage 3</div>
                <div class="image-desc">12x24 Vinyl High Wall Dutch Barn</div>
            </div>
        </li>
    
        <li>
            <a class="thumb" href="images/garages/1car1story4.png">
                <img src="images/garages/1car1story4.png" alt="1 Car 1 Story Garage 4" height="100px" width="130px" class="slideshow-img" />
            </a>
            <div class="caption">
                <div class="image-title">1 Car 1 Story Garage 4</div>
                <div class="image-desc">14x24 Vinyl A-Frame with optional tin roof</div>
            </div>
        </li>
    </ul>
    </div>
    
    1辆车1层车库
    
    • 1辆车1层车库1 带可选冲天炉的12x24乙烯基A型框架
    • 1辆车1层车库2 12x24 Duratemp A型框架,带可选Stockton玻璃
    • 1辆车1层车库3 12x24乙烯基高墙荷兰谷仓
    • 1辆车1层车库4 14x24乙烯基A型框架,可选锡制车顶

    我抓取了更具体的div id,并在
    removeChild
    命令中使用了该变量。(x和y变量最初也设置为0)。

    我抓取了更具体的div id,并在
    removeChild
    命令中使用了该变量。(x和y变量最初也设置为0)