0

例如:我有这个字符串

@[1234:peterwateber] <b>hello</b> <div>hi!</div> http://stackoverflow.com

我想把它转换成这样的 HTML:

<a href="1234">@peterwateber</a> &lt;b&gt;hello&lt;/b&gt; &lt;div&gt;hi!&lt;divb&gt; 
<a href="http://sackoverflow.com">http://stackoverflow.com</a>

我正在使用 QueryPath,并且我有这段代码,您可以在其中将“@[123:peterwateber]”中的文本分别输出到“ 123peterwateber ”。

The code to do that is:
$hidden_input = "@[1234:peterwateber] <b>hello</b> <div>hi!</div> http://stackoverflow.com";
preg_match('#@\[(\w+)\:(\w+)\]#', $hidden_input, $m); //returns 123,peterwateber

我想要实现的是拥有这种输出: Facebook 风格帖子或 Twitter 风格帖子

我正在使用 Hawkee 的 jQuery 自动完成插件http://www.hawkee.com/snippet/9391/

4

1 回答 1

2

我不确定是否有专门的功能,但你可以做的是:在链接的例子中(a href)

$raw = "@[1234:peterwateber]"
$thingtoreplace = ("@[");
$firstpass = str_replace($thingtoreplace, "<a href='", $raw);
$raw2 = $firstpass
$thingtoreplace = (":");
$secondpass = str_replace($thingtoreplace, "'>", $raw1);
$raw3 = $second
$thingtoreplace = ("]");
$secondpass = str_replace($thingtoreplace, "'</a>", $raw3);

我知道这看起来很乏味,但它应该可以解决问题。如果它没有帮助那么请不要给我打分...我花了时间在这

于 2012-04-07T05:04:11.390 回答