忽略标题标签中的上标

发布于 2024-07-10 16:17:31 字数 295 浏览 14 评论 0原文

我在一个数据库驱动的网站上工作。 大多数页面的标题是我们拥有的合作伙伴的名称,并使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

他夏了夏天 2024-07-17 16:17:31

对于:

<title><?php echo $offer22name ?>is a magazine</title>

更改为:

<title><?php echo preg_replace('|<sup>(.*?)</sup>|', '($1)', $offer22name) ?> is a magazine</title>

但就像 Bryan 提到的,在这种情况下您应该使用 PHP 的 strip_tags() 。 所以:

<title><?php echo strip_tags($offer22name) ?> is a magazine</title>

For:

<title><?php echo $offer22name ?>is a magazine</title>

change to:

<title><?php echo preg_replace('|<sup>(.*?)</sup>|', '($1)', $offer22name) ?> is a magazine</title>

But like Bryan mentioned, you should use PHP's strip_tags() in this scenario. So:

<title><?php echo strip_tags($offer22name) ?> is a magazine</title>
泛滥成性 2024-07-17 16:17:31

在将其作为标题发布之前,使用 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.

稚气少女 2024-07-17 16:17:31
<title><?PHP echo str_replace('<sup>tm</sup>', '™', $offer22name); ?> is a magazine</title>

或者,更安全:

<title><?PHP echo strip_tags(str_replace('<sup>tm</sup>', '™', $offer22name)); ?> is a magazine</title>

或者,捕获更多案例(不确定这一点):

<title><?PHP echo strip_tags(preg_replace('/<sup.*?>\s+[Tt][Mm]\s*</(sup|)>', '™', $offer22name)); ?> is a magazine</title>

您可以将 '™' 替换为 '™' >、'™' 或 '™'(但要确保编码与最后一个编码匹配),具体取决于具体情况。

<title><?PHP echo str_replace('<sup>tm</sup>', '™', $offer22name); ?> is a magazine</title>

Or, more safer:

<title><?PHP echo strip_tags(str_replace('<sup>tm</sup>', '™', $offer22name)); ?> is a magazine</title>

Or, catching more cases (not sure on this one exactly):

<title><?PHP echo strip_tags(preg_replace('/<sup.*?>\s+[Tt][Mm]\s*</(sup|)>', '™', $offer22name)); ?> is a magazine</title>

You can replace the '™' with '™', '™', or '™' if you wish (but make sure encodings match for the last one), depending on the situation.

甜`诱少女 2024-07-17 16:17:31

不是 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?

沒落の蓅哖 2024-07-17 16:17:31

一句话,不。

理想情况下,您会执行 $partnername22 = strip_tags('DiscovertmMagazine'); (或更奇特的内容),但如果您不能这样做,那么恐怕您被 Javascript 解决方案困住了。

就像是:

window.title = window.title.replace(/<sup.*?</sup>/, '');

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:

window.title = window.title.replace(/<sup.*?</sup>/, '');
昔梦 2024-07-17 16:17:31

PHP 中的正则表达式将替换 text with (text):

$title = preg_replace('|<sup>(.*?)</sup>|', '\($1\)', $title);

这与在 javascript 中执行此操作类似。

Regular Expression in PHP that will replace <sup>text</sup> with (text):

$title = preg_replace('|<sup>(.*?)</sup>|', '\($1\)', $title);

It would be similar to do this in javascript.

月野兔 2024-07-17 16:17:31

迈克,我想你的意思是这样的:

$title = preg_replace('|<sup>(.*?)</sup>|', '$1', $title);

你之前的方式是在标记的单词周围打印一些斜线和括号。 正确的?

您也可以这样做。

$title = preg_replace('|<sup>(.*?)</sup>|', '', $title);

pg,如果您想从标题中完全删除上标信息,

Mike, I think you meant this:

$title = preg_replace('|<sup>(.*?)</sup>|', '$1', $title);

The way you had it before prints some slashes and parenthesis around the tagged word. Right?

pg, you could also just do

$title = preg_replace('|<sup>(.*?)</sup>|', '', $title);

if you wanted to completely remove the superscripted info from the title.

彼岸花ソ最美的依靠 2024-07-17 16:17:31

一些 CSS 的简单权宜之计怎么样?

h2.title sub, h2.title sup { vertical-align: baseline; font-size:100%; }

How about the simple expedient of some CSS?

h2.title sub, h2.title sup { vertical-align: baseline; font-size:100%; }
煮茶煮酒煮时光 2024-07-17 16:17:31

您可以使用字符编码代替标签,例如

You can use character encoding instead of the tag, e.g. ,

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文