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

Prevent Widows with PHP and?JavaScript

WBOY
发布: 2016-06-06 20:12:49
原创
1310 人浏览过

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!

相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门推荐
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板