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

Prevent Widows with PHP and?JavaScript

WBOY
WBOY원래의
2016-06-06 20:12:491322검색

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, '?');
// With PHP
$text = preg_replace( '|([^\s])\s+([^\s]+)\s*$|', '$1?$2', $text);

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!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.