【发布时间】:2012-12-27 11:07:09
【问题描述】:
我不知道这是否可行,但我有一段纯文本,其中始终包括:
http://www.royalmail/portal/etc/etc/track.php?trackNumber=123345323
当从数据库拖到我的页面时,这显然不会呈现为链接。有什么方法可以选择这段文本(即通过http://)并在最基本的情况下用锚标签包装它 - 或者更复杂的是 - 检索地址,用锚标签包装地址,并更改原始@987654323 @文本到更易于理解的内容,例如“跟踪包裹”
需要注意的是,可能会同时循环出多个跟踪引用。
我的包含HTML如下
<div class="message_holder">
<div class="mess_head" style="width:110px;">
<p><strong>Sender: </strong><? echo $row11['sender'];?></p>
</div>
<div class="mess_head" style="width:450px;">
<p><strong>Subject: </strong><span class="red"><? echo $row11['subject'];?></span></p>
</div>
<div class="mess_head" style="width:150px;">
<p><strong>Date Sent: </strong><? echo date('d/m/Y, H.ia', $row11['date_sent']);?></p>
</div>
<div class="mess_head" style="width:200px;">
<p><strong>Message ID: </strong><? echo $row11['message_id'];?></p>
</div>
<div class="mess_body">
<p><? echo html_entity_decode($row11['message']);?></p>
</div>
</div>
纯文本链接将全部显示在“mess_body”类中。我试过使用html_entity_decode(),但这并没有成功。如果有一种简单的方法可以通过 PHP 而不是 JQuery 做到这一点,它可能会更简单。
【问题讨论】:
-
您应该使用 PHP 而不是 Javascript 来执行此操作。为什么你不能只做
<a href="<? echo html_entity_decode($row11['message']);?>">Track Parcel</a>? -
链接引用包含在其他纯文本中,因此需要将其标识为链接。
标签: php jquery jquery-selectors