PHP URL标题看起来很有趣

时间:2017-09-28 10:31:32

标签: php

以下代码为我提供了一个链接标题"%20"而不是空格并添加" http://"在标题之前。

" user_url"是链接网址。

"标语"是标题文本(例如" Lorem ipsum dolor sit amet,consectetur adipiscing elit ...")

输出结果为:" http://Lorem&20ipsum&20dolor&20sit&20amet&20consectetur&20adipiscing&20elit"

我想要的只是干净的文字。

有什么建议吗?

以下是代码:



public function newAulaAssistida($idProfessorA, $idProfessorB, $dataA, $dataB, $discA, $discB, $anoA, $anoB){
    try{
        $stmt = $this->db->query("INSERT INTO aulasassistidas (dataRegistado) VALUE (NOW());");
        $result= $stmt->execute();
        if (!$result) {
            print_r($stmt->errorInfo());
            return array('status' => 'error', 'message' => Error');
        }
        else{
            return array('status' => 'success', 'message' => '0k');
        }
    }catch (Exception $ex) {
        echo $ex->getMessage();
    }
}




谢谢! :)

2 个答案:

答案 0 :(得分:2)

那是因为你在网址上逃避了你的标题:

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

应该有用。

答案 1 :(得分:2)

最好使用htmlentities(),因为标题需要在双引号之间转义,因为如果文本本身恰好包含双引号,它将破坏标题甚至搞乱html标记的功能。见http://php.net/manual/en/function.htmlentities.php

  

htmlentities - 将所有适用的字符转换为HTML实体

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

我更喜欢在ENT_QUOTES - 函数的第二个参数flags中使用htmlentities()引用双引号和单引号。有关可用标志,编码参数等的详细信息,请查看文档链接。

相关问题