Solved

preg_match value wrapped in HTML tags

Posted on 2007-04-04
10
325 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
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.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

810 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