Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

preg_match value wrapped in HTML tags

Posted on 2007-04-04
10
Medium Priority
?
334 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 200 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 1800 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
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.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
Suggested Courses

636 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