preg_match value wrapped in HTML tags

it is possible to perform something like this but a working solution:

if(preg_match("/<span style=\"\">(*.)</span>/i",$original))
      $original = str_replace('<span style="">(*.)</span>','',$original);

also i want to remove any </span> tags that "dont" have a opening <span>
LVL 16
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

you are you trying to match ?? are you trying to remove all <span that have a style attr. ?
> also i want to remove any </span> tags that "dont" have a opening <span>
Not possible until you write a simple parser which can detect closing spans/tags. But what next. Which is the wrong closing tag that should be removed? As the spans can be nested the whole thing must use a stack which is not possible with regular expressions.

To replace the content of all spans which have an empty style use:
$original = preg_replace('/\<span style=""\>(*.?)\<\/span\>/i',$original)
^ same question.

If you're trying to remove all with a style attr:

$original = preg_replace('#<span style=".*?">.*?</span>#si', '', $original);

To remove ALL <span></span> tags:

$original = preg_replace('#<span[^>]*?>.*?</span>#si', '', $original);
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

ellandrdAuthor Commented:
i cant get any of these example working.
ellandrdAuthor Commented:
my page returns no errors either - its just blank.
ellandrdAuthor Commented:
is it possible to keep the value  between the <span style=""></span> or <span></span>?
ellandrdAuthor Commented:
>>you are you trying to match ?? are you trying to remove all <span that have a style attr. ?

say i have this string:

$original = 'Some <span style="">value</span> that is wrapped with empty span tags';

well i want to remove the empty <span style=""></span> but keep the value in-between.
preg_replace('#<span style="(.*?)">(.*?)</span>#si', '\\2', $original);

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ellandrdAuthor Commented:
please explain what this does as when i run this preg_replace() nothing is happening.. i still get Some <span style="">value</span> as the output
ellandrdAuthor Commented:
ah - its needs a $original = preg_replace();

works now - thank you.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.