简体   繁体   中英

Regular expression, replace between “<” and “>”, php

I'm very weak in regular expressions.

I simply need to replace < and > (and anything between) with new content.

This is what I have:

$key = preg_replace('/<.*>/', '', $key);

My little string <5> should simply be My little string .
My little string <96> should simply be My little string .

What did I do wrong?

The following works if you supply the string instead of $key :

preg_replace('/<.*>/', '', 'My little string <96>');

What is the value of $key ?

$key必须等于要替换的字符串。正则表达式没有任何问题。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM