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!

Recommended Answers

All 3 Replies

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".

commented: Thanks +0

Great!

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

did the job.
Thanks sepp2k!

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.