2011-06-26 12:16

PHP:转换HTML以在标记中的alt / title属性中使用并保持格式


Essentially I have this

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

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.

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 :)

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • dskzap8756 dskzap8756 10年前

    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.

    点赞 6 评论 复制链接分享
  • doumixiang2227 doumixiang2227 10年前

    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.

    点赞 评论 复制链接分享