1

Hello
First of all, I'm new to PHP, and also to Daniweb.
I've been looking everywhere for some PHP code to skip to the next line every time my string ($description) has a period in it. So here's an example of what I want to achieve:

Text:
The car is green. The tree is yellow
What I want it to be:
The car is green.
The tree is yellow.

Thanks in advance!

3
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by Dani
1

You can use the str_replace function to replace each occurence of "." in $description with ".\n", i.e. to insert a newline (\n) after each period. If you want to display your string as HTML, you should use "<br>" instead of (or in addition to) "\n".

Votes + Comments
Thanks
0

Great!

$description=str_replace('.','.<br/>', $description);

did the job.
Thanks sepp2k!

0

I've gone ahead and marked this question solved. In the future, click the 'Mark Question Solved' button right below the reply. This gives sepp2k credit and also adds this question to our knowledge base of solved Q&As for future reference by others.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.