Solved

php strip empty html tags

Posted on 2011-02-14
5
394 Views
Last Modified: 2012-05-11
Hi Experts!

With Curl my script receives HTML code from a website. From that source I would like to strip all empty tags such as <p> </p>

Somehow I can't seem to remove them, I think it has something to do with character settings or something. This is what I've tried:

$html = preg_replace('/<[^\/>]*>([\s]?)*<\/[^>]*>/','' , $html);
$html = preg_replace('%<p></p>%','' , $html);
$html = preg_replace('%<p> </p>%','' , $html);
$html = str_replace('<p> </p>','',$html);

Any suggestions?
0
Comment
Question by:Dennie
  • 3
5 Comments
 
LVL 9

Expert Comment

by:sshah254
ID: 34889418
I think the syntax should be

$html = preg_replace('\<p>\<\p>','' , $html);

to remove <p></p>

Ss
0
 

Author Comment

by:Dennie
ID: 34889438
nope not working
0
 

Accepted Solution

by:
Dennie earned 0 total points
ID: 34889493
Ah solved it with my good old regex buddy!
$html = preg_replace('/<[^\/>]*>([\x00\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8A\x8B\x8C\x8D\x8E\x8F\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9A\x9B\x9C\x9D\x9E\x9F\xA0]?)*<\/[^>]*>/','' , $html);

Open in new window

0
 
LVL 38

Expert Comment

by:Aaron Tomosky
ID: 34889502
I think you have to escape every less than and greater than  and slash.
\<p\>\<\/p\>
0
 

Author Closing Comment

by:Dennie
ID: 34932104
Solved the problem :)
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
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 learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

747 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

13 Experts available now in Live!

Get 1:1 Help Now