Solved

preg_match value wrapped in HTML tags

Posted on 2007-04-04
10
321 Views
Last Modified: 2008-02-01
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>
0
Comment
Question by:ellandrd
10 Comments
 
LVL 20

Expert Comment

by:steelseth12
ID: 18851981
you are you trying to match ?? are you trying to remove all <span that have a style attr. ?
0
 
LVL 48

Assisted Solution

by:hernst42
hernst42 earned 50 total points
ID: 18852075
> 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)
0
 
LVL 4

Assisted Solution

by:secondv
secondv earned 450 total points
ID: 18852090
^ 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);
0
 
LVL 16

Author Comment

by:ellandrd
ID: 18852993
i cant get any of these example working.
0
 
LVL 16

Author Comment

by:ellandrd
ID: 18852999
my page returns no errors either - its just blank.
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 16

Author Comment

by:ellandrd
ID: 18853027
is it possible to keep the value  between the <span style=""></span> or <span></span>?
0
 
LVL 16

Author Comment

by:ellandrd
ID: 18853075
>>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.
0
 
LVL 4

Accepted Solution

by:
secondv earned 450 total points
ID: 18853393
preg_replace('#<span style="(.*?)">(.*?)</span>#si', '\\2', $original);
0
 
LVL 16

Author Comment

by:ellandrd
ID: 18856038
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
0
 
LVL 16

Author Comment

by:ellandrd
ID: 18856049
ah - its needs a $original = preg_replace();

works now - thank you.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now