Solved

preg_match value wrapped in HTML tags

Posted on 2007-04-04
10
329 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
Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

 
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

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Question has a verified solution.

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

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
This article discusses how to implement server side field validation and display customized error messages to the client.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

726 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