Solved

<p> Encapsulation </p>

Posted on 2006-11-06
3
264 Views
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
0
Comment
Question by:blizzdek
[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
  • 2
3 Comments
 
LVL 54

Accepted Solution

by:
b0lsc0tt earned 50 total points
ID: 17885963
blizzdek,

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.

b0lsc0tt
0
 

Author Comment

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

Expert Comment

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

bol
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
This article discusses how to create an extensible mechanism for linked drop downs.
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…
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…

726 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