Maison > php教程 > php手册 > Prevent Widows with PHP and?JavaScript

Prevent Widows with PHP and?JavaScript

WBOY
Libérer: 2016-06-06 20:12:49
original
1320 Les gens l'ont consulté

Read the full article at: Prevent Widows with PHP andJavaScript One of the small touches you can add to your website is preventing widows in your H1 - H6 tags. ?For those who arent aware, a widow (in terms of text and headings) means only

Read the full article at: Prevent Widows with PHP and JavaScript

Treehouse
Wufoo

One of the small touches you can add to your website is preventing “widows” in your H1-H6 tags. ?For those who aren’t aware, a widow (in terms of text and headings) means only one word of a title wraps to the next line — a bit of an ugly sight if you ask me. ?The way to prevent widows with just text is by adding a   between the last two words of the text instead of a regular space character. ?Here are two snippets for preventing widows in your website: ?one?using JavaScript and another using PHP!

// With JavaScript
var text = text.replace(/\s(?=[^\s]*$)/g, '?');
Copier après la connexion
// With PHP
$text = preg_replace( '|([^\s])\s+([^\s]+)\s*$|', '$1?$2', $text);
Copier après la connexion

As I mentioned originally, widows are not necessarily a bug, but a?small visual quirk that just doesn’t look great. ?Keep these regex usages?handy so you can prevent such a smudge!

Étiquettes associées:
source:php.cn
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Recommandations populaires
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal