复制要在另一个对象上使用的对象中的文本

时间:2017-05-13 07:28:49

标签: php

嘿伙计你可以看到下面的代码 我想要"这个文字是固定的"被复制到所有"这是一个文本"在剩下的部分由PHP

package com.gati.dsalgo.string;

class BST {

    BSTNode root;

    public BST() {
        root = null;
    }

    void insertNames(int data, String name, double salary) {
        root = insertNames(root, data, name, salary);
    }

    BSTNode insertNames(BSTNode root, int data, String name, double salary) {
        if (root == null) {
            root = new BSTNode();
            root.setName(name);
            return root;
        }

        if (name.compareTo(root.getName()) < 0)
            root.setLeft(insertNames(root.getLeft(), data, name, salary));
        else if (name.compareTo(root.getName()) >= 0)
            root.setRight(insertNames(root.getRight(), data, name, salary));

        return root;
    }
}

public class Main1 {
    public static void main(String[] args) {

        BST alpha = new BST();
        alpha.insertNames(0, "Roy", 0);
        alpha.insertNames(0, "Joseph", 0);
        System.out.println("hello");
    }
}

class BSTNode {
    private String name;
    BSTNode left;
    BSTNode right;

    public void setName(String name) {
        this.name = name;

    }

    public void setRight(BSTNode right) {
        this.right = right;
    }

    public void setLeft(BSTNode left) {
        this.left = left;
    }

    public BSTNode getRight() {

        return right;
    }

    public BSTNode getLeft() {
        return left;
    }

    public String getName() {

        return name;
    }

}

1 个答案:

答案 0 :(得分:0)

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

 <?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;
     ?>