Solved

Getting rid of text in <h*> tags

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

743 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