PHP:转换HTML以在标记中的alt / title属性中使用并保持格式
Essentially I have this
<p>hello</p>
<p>So I wanted just to say hi</p>
<p>I hope its going well</p>
Coming from a db.
If I just strip the tags then in the title I get this
title="helloSo I wanted just to say hiI hope its going well"
What I want (like SO does it).
title="Hello
So I wanted just to say hi
I hope its going well"
I have tried using
or
and it just shows up in the title text.
title="Hello
So I wanted just to say hi
I hope its going well"
Is this possible because of using Markdown and the way SO is saving the text?
I'm using TinyMCE and I have looked into ways of formatting the text, I've even tried using the output buffer to try and arrange the text how I want it.
Edit: Lets make this really clear and simple. It's going into a TITLE element!
If I can't get this to work, I'll just do this via a popup with jQuery.
Any help / advise appreciated :)
基本上我有这个 p>
&lt; p&gt; hello&lt; / p&gt;
&lt; p&gt;所以我只想说嗨&lt; / p&gt;
&lt; p&gt;我希望它顺利进行&lt; / p&gt;
code> pre>
来自db。 p>
如果我只是剥离标签然后在标题中我得到这个 p>
title =“helloSo我想要的只是 要说hiI希望它顺利进行“
code> pre>
我想要的是什么(就像SO那样 strong>)。 p>
title =“Hello
所以我只想说嗨
我希望它顺利”
code> pre>
我尝试过使用 \ n或
code>,它只显示在标题文本中。 p>
title =“Hello
我只想说嗨
I 希望它顺利进行“
code> pre>
这是否可行,因为使用了 Markdown strong>以及SO保存文字的方式? p> \ n
我正在使用TinyMCE,我已经研究了格式化文本的方法,我甚至尝试使用输出缓冲区来尝试排列文本如何 我想要它。 p>
编辑:让我们清楚而简单。 它将进入一个TITLE元素! strong> p>
如果我无法使用它,我将通过jQuery弹出窗口执行此操作。 p >
任何帮助/建议表示赞赏:) p>
div>
In PHP, The string '
'
is interpreted just like that and consist of four letters. The string "
"
is interpreted as escape sequences and contains two characters, a carriage return and a linefeed. Use double quotes if you want to insert a line break in a string.
If I recall correctly, browsers won't render alt/title tags with multiple lines? It will simply remove the line spacing.
If they do now, then PHP requires you to wrap \t and other formatting in " double quotations as Sjoerd suggested.