Solved

Getting rid of text in <h*> tags

Posted on 2006-11-26
1
267 Views
Last Modified: 2006-11-29
Hello,

I would like to return plain text from a string (taken from a web page) with ALL content found inside of <h*></h*> tags removed.

So This:
           <h1>Hello World</h1>
           This <em>is</em> a test &amp; only <br /> a test.
           <h3 align=center>Sub <font color=red>Heading</font></h3>
           One two three.
           <h6>Goodbye</h6>

should become:
           This is a test &amp; only a test. One two three.

How can this be done?

strip_tags leaves the text inside the h tags.

Thanks!
0
Comment
Question by:hankknight
1 Comment
 
LVL 19

Accepted Solution

by:
VoteyDisciple earned 500 total points
ID: 18015492
It looks like you want to eliminate the <em> too?

$string = preg_replace('/<h[1-9]>.*?</h[1-9]>/', '', $string);

... should work fine on valid HTML.  A call to strip_tags() afterward would then drop the other tags you cut out, leaving the text inside.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
The viewer will learn how to dynamically set the form action using jQuery.
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…

947 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

23 Experts available now in Live!

Get 1:1 Help Now