无法正确连接字符串中的修剪功能

时间:2019-04-05 12:11:17

标签: php

我有一个字符串“班加罗尔的第一手语”。我想使用php中的trim函数删除此字符串中的撇号。在下面的代码中,此字符串被称为标题变量,以了解更多信息。

function readMoreFunction($heading, $story_desc,$link,$targetFile,$id) 
{  
    //Number of characters to show  
    $chars = 512;  
    $story_desc = strip_tags($story_desc);
    $story_desc = substr($story_desc,0,$chars);  
    $story_desc = substr($story_desc,0,strrpos($story_desc,' '));  
  // Concatenation issue
  $story_desc = $story_desc." <a target='_blank' aria-label='Read More - 
  ".trim($heading, '"')."' href='".$link."/".$targetFile."/".$id."'>Read 
  More...</a>";  
    return $story_desc;  
}

预期结果

 <a target='_blank' aria-label='Read More Bengalurus 1st Sign Language' href='https://yahoo.com/story/16558'>Read More</a>

2 个答案:

答案 0 :(得分:0)

像这样使用

$heading ="Read More Bengaluru's 1st Sign Language";
echo $goodUrl = str_replace("'", '', $heading);

答案 1 :(得分:0)

以下是我找到的解决方案。

function readMoreFunction($heading, $story_desc,$link,$targetFile,$id) 
{  
    //Number of characters to show  
    $chars = 512;  
    $story_desc = strip_tags($story_desc);
    $story_desc = substr($story_desc,0,$chars);  
    $story_desc = substr($story_desc,0,strrpos($story_desc,' '));  

    $ariaLabel = "Read More - ".htmlspecialchars($heading,ENT_QUOTES); 

    $story_desc = $story_desc." <a target='_blank' aria-label='".$ariaLabel."' href='".$link."/".$targetFile."/".$id."'>Read More...</a>";  
    return $story_desc;  
}