如何插入< br>对于我动态生成的字符串? [英] How to insert a <br> for string that I dynamically generated?
问题描述
我想在一个长字符串中插入一个break。
例如字符串是PHP Reference:Beginner to Intermediate PHP 5。
我想要实现的是要显示的字符串,如下所示(请记住我从API源获取此信息):
PHP参考:
初级到中级PHP 5
任何帮助将不胜感激。
谢谢
我的尝试:
我尝试了什么:
& var text =这是测试目的;
text.replace(' ','< br>');
但是我不确定这对我的方案有什么用。
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.
推荐答案
在PHP中:
ECHO str_replace(': ', ': <br>', 'PHP Reference: Beginner to Intermediate PHP 5');
将是一种方法。
你的例子将取代所有''你的所有单词都在一个列表中,每行一个单词。在进行更换时,确保正确且唯一地确定目标非常重要。通常没有单一的刺痛和替换通常是其目标及其修改。
有时您会替换搜索字符串中的所有字符,有时您不会。
这是很多解析问题的关键。 &NBSP;当他们变得艰难的时候会有RegEx,这本身就是一种特殊技能。
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.
这篇关于如何插入< br>对于我动态生成的字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!