?
Solved

<p> Encapsulation </p>

Posted on 2006-11-06
3
Medium Priority
?
266 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 200 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

Video: Liquid Web Managed WordPress Comparisons

If you run run a WordPress, you understand the potential headaches you may face when updating your plugins and themes. Do you choose to update on the fly and risk taking down your site; or do you set up a staging, keep it in sync with your live site and use that to test updates?

Question has a verified solution.

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

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…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

777 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