忽略标题标签中的上标
我在一个数据库驱动的网站上工作。 大多数页面的标题是我们拥有的合作伙伴的名称,并使用 php 从数据库提供。
例如,一页可能称为“Experian”。 问题是合作伙伴名称的某些值不起作用,因为这些值就像
$partnername22 = Discover<sup>tm</sup> Magazine
我不能将其用于标题,因为上标不能显示在标题中,并且我无法更改该值,因为许多其他事情都取决于它。 我可以使用一个技巧来使浏览器忽略标题中的上标标签吗?
I work on a database driven website. Most pages' titles are the names of partners we have, and served from a database using php.
For example one page might be called "Experian". The problem is that some of the values for partner names don't work because the values are things like
$partnername22 = Discover<sup>tm</sup> Magazine
I can't use this for a title because superscript can't show up in a title, and I can't change the value because many other things depend on it. Is there a trick I can pull to make the browser ignore the superscript tags if they are in the title?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
对于:
更改为:
但就像 Bryan 提到的,在这种情况下您应该使用 PHP 的 strip_tags() 。 所以:
For:
change to:
But like Bryan mentioned, you should use PHP's strip_tags() in this scenario. So:
在将其作为标题发布之前,使用 PHP 的 strip_tags() 命令从字符串中删除所有 html 是非常简单的(可能也是明智的)。
It would be very simple (and probably advisable) to use PHP's strip_tags() command to remove all of the html from your string before posting it as a title.
或者,更安全:
或者,捕获更多案例(不确定这一点):
您可以将
'™'
替换为'™'
>、'™'
或 '™'(但要确保编码与最后一个编码匹配),具体取决于具体情况。Or, more safer:
Or, catching more cases (not sure on this one exactly):
You can replace the
'™'
with'™'
,'™'
, or '™' if you wish (but make sure encodings match for the last one), depending on the situation.不是 AFAIK,但是如果您已经从数据库中编写了字符串脚本,为什么不能编写相同的字符串正则表达式,用空字符串替换标签(或标签对,如您所愿)?
Not AFAIK, but if you're already scripting out a string from the DB, why can't you script out the same string regex replacing tags (or tag pairs, as you wish) with empty strings?
一句话,不。
理想情况下,您会执行
$partnername22 = strip_tags('DiscovertmMagazine');
(或更奇特的内容),但如果您不能这样做,那么恐怕您被 Javascript 解决方案困住了。就像是:
In a word, no.
Ideally you would do
$partnername22 = strip_tags('Discover<sup>tm</sup> Magazine');
(or something fancier), but if you can't to that then I'm afraid you're stuck with a Javascript solution.Something like:
PHP 中的正则表达式将替换 text with (text):
这与在 javascript 中执行此操作类似。
Regular Expression in PHP that will replace <sup>text</sup> with (text):
It would be similar to do this in javascript.
迈克,我想你的意思是这样的:
你之前的方式是在标记的单词周围打印一些斜线和括号。 正确的?
您也可以这样做。
pg,如果您想从标题中完全删除上标信息,
Mike, I think you meant this:
The way you had it before prints some slashes and parenthesis around the tagged word. Right?
pg, you could also just do
if you wanted to completely remove the superscripted info from the title.
一些 CSS 的简单权宜之计怎么样?
How about the simple expedient of some CSS?
您可以使用字符编码代替标签,例如
™
、™
You can use character encoding instead of the tag, e.g.
™
,™