定制 lukaswhite/auto-no-follow 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

lukaswhite/auto-no-follow

Composer 安装命令:

composer create-project lukaswhite/auto-no-follow

包简介

Automatically add rel=nofollow to links in HTML, using PHP

README 文档

README

This simple PHP package has one simple purpose; to take some HTML (as a string), go through it and add rel="nofollow" to all links, subject to certain exceptions.

So give it this:

<p>Check out our <a href="http://example.com">affordable web design services</a>!</p>

...and you get this:

<p>Check out our <a href="http://example.com" rel="nofollow">affordable web design services</a>!</p>

By default, it will ignore relative links, so this would remain untouched:

<p>Check out the <a href="/about">about</a> page</p>

It will also ignore absolute links to the current domain.

You can also provide a whitelist of domains, and it will skip them.

Installation

composer require lukaswhite/auto-no-follow

Usage

Create an instance:

$processor = new \Lukaswhite\AutoNoFollow\Processor();

Optionally specify the current host:

$processor->setCurrentHost('example.com');    

If you don't set this, it'll grab it from $_SERVER['HTTP_HOST']

Then run:

$html = $processor->addLinks('<p>Check out our <a href="http://example.com">affordable web design services</a>!</p>');

The method signature is this:

public function addLinks($html, $whitelist = array(), $ignoreRelative = true)

So, to whitelist certain hosts:

$html = $processor->addLinks(
  '<p>Check out our <a href="http://example.com">affordable web design services</a>!</p>'
  [
  	'example.com'
  ]
);

To add nofollow to relative links anyway, set the third argument to true, e.g.:

$html = $processor->addLinks(
  '<p>Check out the <a href="/about">about</a> page</p>'
  [],
  TRUE
);

This will output the following:

<p>Check out the <a href="/about" rel="nofollow">about</a> page</p>

Tests

The package contains tests, to run them:

./vendor/bin/phpunit

统计信息

  • 总下载量: 11
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-01-14

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固