Click here to Skip to main content
15,918,404 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to insert a break into a long string.

For example string is "PHP Reference: Beginner to Intermediate PHP 5".
What i want to achieve is the string to be displayed as with a break as shown below (keeping in mind I'm getting this info from API source):

"PHP Reference:
Beginner to Intermediate PHP 5"


Any help would be appreciated.
Thanks

What I have tried:

What i have tried:

&var text= This is test "purpose";
text.replace('"', '<br>"');

But I'm not sure how this will work with my scenario.
Posted
Updated 26-Dec-18 0:42am
v2
Comments
[no name] 25-Dec-18 13:13pm    
Read all again and think about all again.

What this should be?
&var text= This is test "purpose";

1 solution

In PHP:
ECHO str_replace(': ', ': <br>', 'PHP Reference: Beginner to Intermediate PHP 5');
would be one way to do it.

Your example would replace all ' ' and you'd have all of your words in a single list, one word per row. When doing a replace it is important to make sure you have correctly and uniquely determined your target. Often not a single sting and replace is often that target with its modifications.

Sometimes you replace all the chars in the search string and sometimes you don't.

That's the key to a lot of parsing problems.   And when they get tough there's RegEx, which in and of itself is a special skill.

 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900