kasp3r/link-preview
最新稳定版本:v2.0.0
Composer 安装命令:
composer require kasp3r/link-preview
包简介
Link preview library for PHP
README 文档
README
LinkPreview 
A PHP library to easily get website information (title, description, image...) from given url.
Dependencies
- PHP >= 5.6 (without phpunit it should work on 5.5)
- Guzzle
Installation
composer
To install LinkPreview with composer you need to create composer.json in your project root and add:
{
"require": {
"kasp3r/link-preview": "dev-master"
}
}
Then run
$ wget -nc http://getcomposer.org/composer.phar $ php composer.phar install
Library will be installed in vendor/kasp3r/link-preview
In your project include composer autoload file from vendor/autoload.php
Usage
use LinkPreview\LinkPreview; $linkPreview = new LinkPreview('http://github.com'); $parsed = $linkPreview->getParsed(); foreach ($parsed as $parserName => $link) { echo $parserName . PHP_EOL . PHP_EOL; echo $link->getUrl() . PHP_EOL; echo $link->getRealUrl() . PHP_EOL; echo $link->getTitle() . PHP_EOL; echo $link->getDescription() . PHP_EOL; echo $link->getImage() . PHP_EOL; print_r($link->getPictures()); }
Output
general
http://github.com
https://github.com/
GitHub · Build software better, together.
GitHub is the best place to build software together. Over 10.1 million people use GitHub to share code.
https://assets-cdn.github.com/images/modules/open_graph/github-octocat.png
Array
(
[0] => https://assets-cdn.github.com/images/modules/site/home-ill-build.png?sn
[1] => https://assets-cdn.github.com/images/modules/site/home-ill-work.png?sn
[2] => https://assets-cdn.github.com/images/modules/site/home-ill-projects.png?sn
[3] => https://assets-cdn.github.com/images/modules/site/home-ill-platform.png?sn
[4] => https://assets-cdn.github.com/images/modules/site/org_example_nasa.png?sn
)
###Youtube example
use LinkPreview\LinkPreview; use LinkPreview\Model\VideoLink; $linkPreview = new LinkPreview('https://www.youtube.com/watch?v=8ZcmTl_1ER8'); $parsed = $linkPreview->getParsed(); foreach ($parsed as $parserName => $link) { echo $parserName . PHP_EOL . PHP_EOL; echo $link->getUrl() . PHP_EOL; echo $link->getRealUrl() . PHP_EOL; echo $link->getTitle() . PHP_EOL; echo $link->getDescription() . PHP_EOL; echo $link->getImage() . PHP_EOL; if ($link instanceof VideoLink) { echo $link->getVideoId() . PHP_EOL; echo $link->getEmbedCode() . PHP_EOL; } }
Output
youtube
https://www.youtube.com/watch?v=8ZcmTl_1ER8
http://gdata.youtube.com/feeds/api/videos/8ZcmTl_1ER8?v=2&alt=jsonc
Epic sax guy 10 hours
I had to remove my original one so I reuploaded this with much better quality.
(If you want it sound like previous one, try setting quality to 240p)
Yeah, I know that video sucks compared to original but no can do :(
http://i1.ytimg.com/vi/8ZcmTl_1ER8/hqdefault.jpg
8ZcmTl_1ER8
<iframe id="ytplayer" type="text/html" width="640" height="390" src="http://www.youtube.com/embed/8ZcmTl_1ER8" frameborder="0"/>
Todo
- Add more unit tests
- Update documentation
- Add more parsers
License
The MIT License (MIT)
Copyright (c) 2013 Tadas Juozapaitis kasp3rito@gmail.com
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
kasp3r/link-preview 适用场景与选型建议
kasp3r/link-preview 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 80.4k 次下载、GitHub Stars 达 76, 最近一次更新时间为 2013 年 12 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「url」 「scraping」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 kasp3r/link-preview 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 kasp3r/link-preview 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 kasp3r/link-preview 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A lightweight, dependency free PHP class that acts as wrapper for Crawlbase API
Easy URL rewrites in your Laravel application
Bing Image Extractor
A Laravel helper to detect if the current route/path is active.
Provides a service and twig extension for getting short urls like http://your.host/~short
An SDK designed for easy usage of the allrival.com website's API
统计信息
- 总下载量: 80.4k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 79
- 点击次数: 23
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2013-12-19