Solved

<p> Encapsulation </p>

Posted on 2006-11-06
3
263 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

Independent Software Vendors: 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!

Question has a verified solution.

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

Suggested Solutions

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
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 create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

730 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