Solved

Getting rid of text in <h*> tags

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

Technology Partners: 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

Suggested Solutions

Title # Comments Views Activity
How to close my php post page. 3 41
Link Stopped Working 7 32
Php variable to be sent back 3 34
foreach loop to only capture results that are greater than 0 16 38
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…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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.

734 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