Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2011-02-18
7
Medium Priority
?
302 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
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 14

Accepted Solution

by:
svgmuc earned 1000 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 1000 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
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…
Suggested Courses

916 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