<p> Encapsulation </p>

Posted on 2006-11-06
Medium Priority
Last Modified: 2012-08-13
Hullo there.
I was wondering if anyone would know how to make a function that takes a string (provided in the parameters) and treats every \n as the end and start of a <p> element (excluding the first occurrence). In other words:

$string = "I am about to be\nprocessed."

would become:

$string = "<p>I am about to be</p><p>processed.</p>"

Thanks for your help, experts
Question by:blizzdek
  • 2
LVL 54

Accepted Solution

b0lsc0tt earned 200 total points
ID: 17885963

I would first try using replace.  You may need to strip the opening paragraph tag from the end of the string though and add a starting paragraph tag.

$string = str_replace("\n","</p><p>", $fullstring);

Let me know if you have any questions or need more information.


Author Comment

ID: 17886003
I can't believe I forgot that str_replace existed. Thanks :D
LVL 54

Expert Comment

ID: 17886060
Your welcome!  I'm glad that I could help.  Thank you for the grade, the points and the fun question.


Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

This article discusses four methods for overlaying images in a container on a web page
This article discusses how to implement server side field validation and display customized error messages to the client.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

600 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