2011-12-08 117 views
0

Ok so I'm circling around this site and people are like "OMG, don't use regexp and html!" Well, I just have a custom field in WP that I want to match anything with a simple "a href=" and indicate that it's there.如何匹配'<a href=' in a string?

I easily get a headache when I start reading about regexp so anyone want to give me a hand?

回答

0

If it's really that simple, you don't need a regex at all. You can do a simple strpos(或stripos不区分大小写)搜索以查看字符串是否包含"a href="

if(strpos($input, 'a href=') !== false) { 
    // stuff 
}