Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,254
Total Threads: 80,792
Total Posts: 566,472
There are 1680 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     Programming     PHP and MySQL :

Stripping <p> tags...

Thread title: Stripping <p> tags...
Closed Thread    
    Thread tools Search this thread Display Modes  
05-27-2008, 06:31 AM
#1
Jako is offline Jako
Jako's Avatar
Status: Jakowenko.com
Join date: Jun 2005
Location: Michigan
Expertise:
Software:
 
Posts: 2,199
iTrader: 3 / 100%
 

Jako is on a distinguished road

  Old  Stripping <p> tags...

I've searched a lot and found some examples, but can't figure out how to use it in my code.

I want to strip the <p> tags from this wordpress excerpt.

The WP code is,

PHP Code:
<?php while (have_posts()): the_post(); ?>
<strong><u><?php the_title(); ?></strong></u>
<?php the_excerpt(); ?>
<strong><a href="<?php the_permalink(); ?>">Read more...</a></strong>
<?php endwhile; ?>

05-27-2008, 07:08 AM
#2
CreativeLogic is offline CreativeLogic
CreativeLogic's Avatar
Status: Request a custom title
Join date: Feb 2005
Location:
Expertise:
Software:
 
Posts: 1,078
iTrader: 6 / 100%
 

CreativeLogic is on a distinguished road

Send a message via MSN to CreativeLogic

  Old

Code:
<?php the_excerpt(); ?>
To this:
Code:
<?php str_replace ('<p>', '', the_excerpt()); ?>
Untested, and doesn't strip the </p> tags, will require a little additional for that.

05-27-2008, 09:34 AM
#3
Llanilek is offline Llanilek
Status: I'm new around here
Join date: May 2008
Location:
Expertise:
Software:
 
Posts: 17
iTrader: 0 / 0%
 

Llanilek is on a distinguished road

Send a message via MSN to Llanilek

  Old

you can either do what CreativeLogic told you.

and add it like this.

Code:
<?php 
str_replace('<p>', '', the_excerpt());
str_replace('</p>', '', "the_except());
?>
that would strip both <p> and </p> tags...

although something a little more productive would be to use regexp.

Code:
<?php

$str = preg_replace('^<p\>(.+)\<\/p\>^', '$1', the_excerpt());

echo $str;

?>
although the preg_replace will only work if the_excerpt(); has a return value not an echo value.

hope this helps some.

05-27-2008, 10:30 AM
#4
Salathe is offline Salathe
Salathe's Avatar
Status: Community Archaeologist
Join date: Jul 2004
Location: Scotland
Expertise: Software Development
Software: vim, PHP
 
Posts: 3,820
iTrader: 25 / 100%
 

Salathe will become famous soon enough

Send a message via MSN to Salathe

  Old

You could try using:
PHP Code:
<?php echo get_the_excerpt(); ?>
I think that strips all HTML and doesn't wrap paragraph tags around the excerpt, but I could be mistaken. If you do get paragraph tags using the above you can just use
PHP Code:
echo preg_replace('~</?p>~i'''get_the_excerpt()); 
You could also look into using a plugin to apply a filter to the calls to the_excerpt() which would negate any need to edit the template file(s).

05-27-2008, 10:40 AM
#5
Gurnk is offline Gurnk
Status: Member
Join date: May 2007
Location: US
Expertise:
Software:
 
Posts: 380
iTrader: 12 / 100%
 

Gurnk is on a distinguished road

Send a message via AIM to Gurnk Send a message via MSN to Gurnk

  Old

There is a Worpdress Plugin called "Wordpress Unformatted" or something like that. I'm not sure if it works for the excerpt, but it is worth a shot.

Closed Thread    


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed