Orangeman555
Orangeman555

Reputation: 1181

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?

Upvotes: 0

Views: 739

Answers (2)

scottlimmer
scottlimmer

Reputation: 2278

$key needs to be equal to the string you are tring to replace in. There is nothing wrong with your regular expression.

Upvotes: 0

Justin O Barber
Justin O Barber

Reputation: 11591

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

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

What is the value of $key?

Upvotes: 1

Related Questions