PHP:如果href包含我的字符串,则preg_replace href

时间:2018-09-16 10:06:02

标签: php html

我想如果我的链接包含name.com,则preg_replace可以正常工作

class Main {
    final static int[] coins = {50, 25, 10, 5, 1};
    static int[][] memo;
    public static void main(String[] args) throws IOException{
        MyScanner sc = new MyScanner();
        Integer num = 7489 + 1;
        memo = new int[num+1][coins.length];
        for (int i = 0; i < num+1; i++) {
           Arrays.fill(memo[i], -1);
        }
        while ((num = sc.nextInt()) != null) {
            int r = change(num, 0);
            System.out.println(r);
        }
    }

    private static int change(int num, int cInd) {
        if (num < 0){
            return 0;
        } else if (num == 0 || cInd == coins.length-1){
            return 1;
        } else if(memo[num][cInd] != -1) {
            return memo[num][cInd];
        }else {
            int result = change(num, cInd+1) + change(num-coins[cInd], cInd);
            return memo[num][cInd] = result;
        }
    }

    static class MyScanner {
        BufferedReader br;
        StringTokenizer st;
        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        public String next() throws IOException {
            if (st == null || !st.hasMoreTokens()) {
                String line = br.readLine();
                if (line == null){
                    return null;
                }
                st = new StringTokenizer(line);
            }
            return st.nextToken();
        }
        public Integer nextInt() throws IOException {
            String next = next();
            if (next != null) {
                return Integer.parseInt(next);
            } else {
                return null;
            }
        }
    }
}

输出

$string = '<a href="test/name.com/new">a</a>
           <a href="test/your.com/new">b</a>';
           echo $string = preg_replace("/<a\s(.+?)>(.+?)<\/a>/is", "<b>$2</b>", $string);

但无法正常工作并替换所有链接

0 个答案:

没有答案