Solved

I need to convert multiple paragraphs to a single line in php

Posted on 2011-02-18
7
294 Views
Last Modified: 2012-05-11
In doing so, I need to strip out all <p> tags and convert all </p> tags to \n I am using a CMS with a calendar, but the ical export, while replacing the </p> with \n isn't putting it all on one line.

here is the code i have originally:
$description = strip_tags(str_ireplace('<br />', '\n', $this->getDescription()));

Open in new window


which was for <br /> I need it to do this for <br /> and </p> AND put it all on one line, no carriage returns.
0
Comment
Question by:acprog2
[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
  • 3
  • 3
7 Comments
 
LVL 14

Expert Comment

by:svgmuc
ID: 34927878
$description = str_ireplace('<br />', '\n', $this->getDescription());
$description = strip_tags(str_ireplace('</p>', '\n', $description));
0
 

Author Comment

by:acprog2
ID: 34927892
half way. now i need the output on a single line. with the \n in place of the br and p tags.
0
 

Author Comment

by:acprog2
ID: 34928042
ok I have come up with this:
$description = trim( preg_replace( '/\s+/', ' ', $this->getDescription() ) );

$description = strip_tags(str_ireplace(array('\r','</p>','<br />'), '\n', $this->getDescription()));

both line work, but not together. the first puts everything on one line, the second replaces my tags properly. but my script is only respecting the second line if both are there, and the first if the second is commented out.
0
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!

 
LVL 14

Accepted Solution

by:
svgmuc earned 250 total points
ID: 34928253
You're saving the result in a variable, and then get it again from the object instance.

$description = trim( preg_replace( '/\s+/', ' ', $this->getDescription() ) );

$description = strip_tags(str_ireplace(array('\r','</p>','<br />'), '\n', $description()));
0
 
LVL 27

Assisted Solution

by:Lukasz Chmielewski
Lukasz Chmielewski earned 250 total points
ID: 34928255
How about
$description = trim( preg_replace( '/\s+/', ' ', $this->getDescription() ) );
$description = strip_tags(str_ireplace(array('\r','</p>','<br />'), '\n', $description));
0
 
LVL 14

Expert Comment

by:svgmuc
ID: 34928700
yeah, sorry, forgot to remove the parentheses
0
 

Author Closing Comment

by:acprog2
ID: 34928894
Thanks, both of you.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Link failure 16 64
$_GET call between URL 3 41
PHP encrypted string and passing to a ASP Page 12 42
PHP Web Development 6 22
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

749 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