Solved

Getting rid of text in <h*> tags

Posted on 2006-11-26
1
269 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

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…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

813 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

11 Experts available now in Live!

Get 1:1 Help Now