2017-09-28 38 views
0

下面的代码给了我一个带有“%20”而不是空格的链接标题,并在标题前加上了“http://”。PHP URL标题看起来很有趣

“user_url”是链接url。

“口号”是的标题文字(如“Lorem存有悲坐阿梅德,consectetur adipiscing ELIT ......”)

输出是:“http://Lorem&20ipsum&20dolor&20sit&20amet&20consectetur&20adipiscing&20elit

我要的只是干净文本。

有什么建议吗?

下面的代码:

<?php if(!empty($current_author_profile->user_url)) {?> 
 
<li><i class="fa fa-link"></i><a href="<?php echo esc_url($current_author_profile->user_url);?>" target="_blank" title="<?php echo esc_url($current_author_profile->tagline);?>"><?php echo docdirect_parse_url($current_author_profile->user_url);?></a></li> 
 
<?php }?>

谢谢! :)

+0

你是什么明文 –

+0

意味着当我将鼠标悬停我想“Lorem存有悲坐阿梅德,consectetur adipiscing ELIT”而不是“HTTP链接;// Lorem&20ipsum&20dolor&20sit&20amet&20consectetur&20adipiscing&20elit“ –

+0

但我认为这个链接应该与连字符 –

回答

2

由于标题需要在双引号之间转义,因此如果使用htmlentities()更好,因为如果文本碰巧包含双引号,它会打破标题甚至搞乱html标签的功能。见http://php.net/manual/en/function.htmlentities.php

ヶ辆 - 转换所有适用的字符为HTML实体

title="<?php echo htmlentities($current_author_profile->tagline, ENT_QUOTES | ENT_HTML5);?>" 

我更喜欢第二个参数htmlentities() -function的flagsENT_QUOTES引用两个双和单引号。请检查文档链接,可用标志的详细信息,编码参数等

+0

这是超出我的知识,但代码的作品,我会相信你说的其余的。谢谢! –

2

那是因为你的网址转义您的标题:

title="<?php echo $current_author_profile->tagline;?>" 

应该工作。

+0

像一个魅力:)谢谢! –