Solved

preg_match value wrapped in HTML tags

Posted on 2007-04-04
10
328 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
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:
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

733 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