版权符号将打印 &®

use*_*779 -2 php

我想在我的 php 页面中使用 ®( ®)。尝试$var ='test'.&#174 .'title';获取站点错误。如何在 php 中使用字符串

php页面中的HTML字符实体

   $vars['head_title'] = 'test'.htmlentities('®').'string title';
Run Code Online (Sandbox Code Playgroud)

在输出中将得到test&®string title 如何在 php 中使用保留符号

tre*_*ake 5

您试图htmlentities错误地使用,取自手册

该函数在所有方面都与 htmlspecialchars() 相同,除了 htmlentities(),所有具有 HTML 字符实体等效项的字符都被转换为这些实体。

如果你想解码(相反),你可以使用 html_entity_decode()。

你想要相反的,html_entity_decode()

<?php
    echo 'test '.htmlentities('&reg;').'string title'; # doesn't work
    echo 'test '.html_entity_decode('&reg;').'string title'; # works
Run Code Online (Sandbox Code Playgroud)

小提琴