简体   繁体   English

从get_meta_tags超链接关键字

[英]Hyperlinking keywords from get_meta_tags

I'm using get_meta_tags to extract keywords from a webpage right now but I need each of those keywords linked to my website when displayed. 我现在正在使用get_meta_tags从网页中提取关键字,但是显示时需要链接到我的网站的每个关键字。

Here's my code: 这是我的代码:

<?php echo $tags['description']; ?><br /><br />
<?php echo $tags['keywords']; ?>

This is the text pulled from HostGator.com for the keywords: 这是从HostGator.com提取的关键字文本:

 web hosting, hosting, webhosting

I need each of those keywords linked to my website like this: 我需要像这样链接到我的网站的每个关键字:

<a href="http://www.mysite.com/keywords/web-hosting">web hosting</a>, 
<a href="http://www.mysite.com/keywords/hosting">hosting</a>, 
<a href="http://www.mysite.com/keywords/webhosting">webhosting</a>

Nothing I've tried seems to be working with this so I was hoping you guys could help out. 我尝试过的所有方法似乎都无法解决这个问题,所以我希望你们能帮上忙。

You have try this way. 您已经尝试过这种方式。

<?php
foreach($data as $tags)
{
    ?><a href="http://www.mysite.com/keywords/web-hosting/"<?php echo $tags['keywords']; ?>><?php echo $tags['keywords']; ?></a><?php
}
?>

I'm assuming you have your tags as text, rather than an array. 我假设您将标签作为文本而不是数组。

$data = 'web hosting, hosting, webhosting';
$tags = explode(', ' , $data);

foreach($tags as $tag) {
    echo '<a href="http://www.mysite.com/keywords/'.$tag.'>'.$tag.'</a>';
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM