Solved

Getting rid of text in <h*> tags

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
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…

635 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