复制对象中的文本以供PHP在另一个对象上使用

复制对象中的文本以供PHP在另一个对象上使用,php,Php,嘿,伙计们,你们可以看到下面的代码 我想通过PHP将“This text is fixed”复制到其余部分中的所有“This is a text” <div class = "movies"> <a href = " This text is fixed "><img src = "This is a text/media/poster.png" alt = "This is a text"><hr color = "blue" size = "3"&g

嘿,伙计们,你们可以看到下面的代码 我想通过PHP将“This text is fixed”复制到其余部分中的所有“This is a text”

<div class = "movies">
<a href = " This text is fixed "><img src = "This is a text/media/poster.png" alt = "This is a text"><hr color = "blue" size = "3"><font><center>This is a Text</center></font></a>
</div>

您可以使用该类来执行此操作

 <?php
    $html="
    <div class ='movies'>
    <a href = 'This text is fixed '>
    <img src = 'This is a text/media/poster.png' alt = 'This is a text'>
    <hr color = 'blue' size = '3'>
    <center>This is a Text</center>
    </a>
    </div>";
    $dom = new DOMDocument;
    $dom->loadHTML($html);
    foreach ($dom->getElementsByTagName('a') as $node) {
        $href= $node->getAttribute( 'href' );
        foreach ($dom->getElementsByTagName('img') as $node) {
        $node->setAttribute('alt',$href);
        }
    }
     echo $dom->saveHtml($dom), PHP_EOL;
     ?>

如果您只想替换文本,请使用任何文本编辑器的查找和替换功能。。如果你想使用PHP脚本,str_replace会有帮助。如果您能准确地展示更换后的外观,并向我们展示您正在尝试的产品,这将是非常棒的。详细信息有点稀少。这是某种模板吗?为什么要使用PHP替换HTML标记中的文本?JavaScript/jQuery不足以胜任这项工作吗?请提供更多的上下文和细节,说明您在这里想要实现的目标。