Reputation: 2531
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?
Upvotes: 2
Views: 4206
Reputation: 1
You can use character encoding instead of the tag, e.g. ™
, ™
Upvotes: -1
Reputation: 3489
How about the simple expedient of some CSS?
h2.title sub, h2.title sup { vertical-align: baseline; font-size:100%; }
Upvotes: 0
Reputation: 90042
<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.
Upvotes: 2
Reputation: 8973
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>
Upvotes: 2
Reputation: 7199
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.
Upvotes: 1
Reputation: 7199
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.
Upvotes: 2
Reputation: 8973
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.
Upvotes: 1
Reputation: 321766
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>/, '');
Upvotes: 1
Reputation: 75862
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?
Upvotes: 1