此处根据其GitHub使用方法
我已经安装了软件包:
使用Opengraph
$data = OpenGraph::fetch("http://www.addemyplus.com/blogs/my-faith-for-your-love");
可能返回数组:
{"type":"website","title":"My Faith For Your Love","description":"","image":"http:\/\/www.addemyplus.com\/images\/frontend_images\/blogs\/medium\/57670.jpg"}
我的问题是如何在刀片上使用它,只要我以该格式键入链接,它将获取该站点的Og数据。
并在图片和说明下方显示
我在表单上有此代码:
<form action="{{route('store_post_path')}}" method="POST">
{{csrf_field()}}
<div class="form-group">
<label class="sr-only" for="title">title</label>
<input type="text" class="form-control" name="title" placeholder="Your Post Title or Question">
</div>
<div class="form-group">
<label class="sr-only" for="post">post</label>
<textarea class="form-control" name="post_content" id="post_content" rows="3" placeholder="Briefly explain your question or Your Post Content"></textarea>
</div>
<div class="tab-pane fade" id="images" role="tabpanel" aria-labelledby="images-tab">
<div class="form-group">
<div class="custom-file">
</div>
</div>
<div class="py-4"></div>
</div>
<div class="btn-toolbar justify-content-between">
<div class="btn-group">
<button type="Submit" class="btn btn-primary">Share your Post</button>
</div>
</div>
</form>
我如何使用代码获取链接的Og属性?在提交我的帖子之前,我想查看下面链接的图像和标题。.请为此显示一些教程站点。
从帖子内容的表单中获取链接。您可以使用正则表达式来完成它。
function getUrl($string)
{
$regex = '/https?\:\/\/[^\" ]+/i';
preg_match_all($regex, $string, $match);
return ($match);
}
$url = getUrl($string)
如果帖子内容中有任何链接,您将获得一系列链接。
使用OpenGraph :: fetch($ url)来获取URL的OG数据。您可以在视图中显示。