承接 spresnac/laravel-url-helper 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

spresnac/laravel-url-helper

Composer 安装命令:

composer require spresnac/laravel-url-helper

包简介

Helping you with URL related problems

关键字:

README 文档

README

Software License PHP from Packagist codecov CI Status

Content:

Installation

First things first, so require the package:

composer require spresnac/laravel-url-helper

Usage

Content Helper

Every time you need to get URLs from some kind of Text or HTML, this class is a helping hand for you.

  1. Make an instance of the class
  2. Use the constructor or the setContent method to put in your content as string.
  3. Get your URLs by using one of the following methods.

getContent(): string

This will just the content you put in via constructor or setContent method.

getHrefs(): Collection

You will retrieve a Collection with only the URLs inside a href

$content_helper = new ContentHelper('insert HTML here');
$result = $content_helper->getHrefs();
// $result is an Collection with all the hrefs in it.

getHrefsAsArray(): array

You will retrieve an array with only the URLs inside a href

$content_helper = new ContentHelper('insert HTML here');
$result = $content_helper->getHrefsAsArray();
// $result is an Collection with all the hrefs in it.

getSrcUrls(): Collection

You will retrieve a collection of urls from src sources.

$content_helper = new ContentHelper('insert HTML here');
$result = $content_helper->getSrcUrls();
// $result is an Collection with all the src-urls in it.

getLinksFromPlaintext(): Collection

This method will try to find all the urls in a plaintext string.

$content_helper = new ContentHelper('insert some plaintext here');
$result = $content_helper->getLinksFromPlaintext();
// $result is an Collection with all the urls from the plaintext in it.

getAllTheLinks(): Collection

This will execute getHrefs, getSrcUrls and getLinksFromPlaintext and will return a uniqueified collection of all the urls.

$content_helper = new ContentHelper('insert some html or plaintext here');
$result = $content_helper->getAllTheLinks();
// $result is an Collection with all the urls.

URL Helper

Some useful helper functions to handle URL related manipulating or info-gatherings.

normalize_url(string $url): string|false

Normalizes URL with .. in it and leaves the all oher URL "as is".

$url_helper = new URLHelper();
$normalized_url = $url_helper->normalize('https://example.com/my/dir/with/two/../init.html');
// $normalized_url is now https://example.com/my/dir/with/init.html

Returns false in case of error

build_url(array $parsed_url): string

This is the missing opposite of parse_url to rebuild a url from its parts.

$url_helper = new URLHelper();
$parsed_url = parse_url('https://example.com/test/url.php');
$my_url = $url_helper->build_url($parsed_url);

getMainDomainPart(string $url): string

This will return the "Main Domain" part of an URL. The "Main Domain" is like the SLD + TLD domain part.

$url_helper = new URLHelper();
$main_domain_part = $url_helper->getMainDomainPart('https://www3.example.com/some/url');
// $main_domain_part is now "example.com"

getSubdomainPart(string $url): string

This will return the Subdomain part of an URL.

$url_helper = new URLHelper();
$sub_domain_part = $url_helper->getMainDomainPart('https://www3.brick.example.com/some/url');
// $sub_domain_part is now "www3.brick"

Sitemap Helper

Handling with web-sitemaps can be handy with some helpers at your side.

process_input_from_string(string $input_string): Collection

Will return all the urls inside a sitemap as Collection

$sitemap_helper = new SitemapHelper();
$urls = $sitemap_helper->process_input_from_string('content_of_your_sitemap_as_string');
// $urls are a collection of all the urls found

process_input_from_url(string $input_url): Collection (0.5+)

Returns the urls in a sitemap url as Collection

$sitemap_helper = new SitemapHelper();
$urls = $sitemap_helper->process_input_from_url('url_to_your_sitemap');
// $urls are a collection of all the urls found

Tests

Simply run

composer test-ci

or

vendor/bin/phpunit 

Finally

Be productive 😉

统计信息

  • 总下载量: 1.08k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-11-11

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固