制作一个单链接的PHP [英] Making A List Of Links With PHP

查看:118
本文介绍了制作一个单链接的PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何使一个链接列表出现在我的网页上显示的名字,但是当你点击它,它定位到的链接。

目前,我知道如何使一个列表,并使用foreach命令和数组显示它的项目,但有什么办法,我可以做,所以我有一个数组,包含数组,包含链接和名称链接本身,就像这样:

  $链接=阵列(阵列(谷歌,// google.co.uk),阵列(冰心,// bing.co.uk) )
的foreach($链接为$ myurl){
的foreach($ myurl为$ URL){
回声&下; A HREF ='$网址。'>中$ myurl&下; / A>中。;
}};

我知道上面不工作,但如果任何人都可以帮助解决这个问题,它是非常AP preciated。


解决方案

  $链接=阵列('谷歌'=>'www.google.com','雅虎'=&GT ;www.yahoo.com');的foreach($链接为$ K => $ V){
  呼应'< A HREF =//'。$ķ。'>' 。 $ V。 '&所述; / A>';
}

正如你可以看到我没有指定 HTTP HTTPS ,只 / / 适用于两个!请参阅: HTTP://google-styleguide.google$c$c .COM / SVN /主干/ htmlcssguide.xml

您可以将链接添加到 $链接

  $链接['计算器'] ='www.stackoverflow.com';

I would like to know how to make a list of links appear on my page displaying a name but when you click it, it navigates to the link.

I currently know how to make a list and display the items of it using the foreach command and arrays but is there a way I can make it so I have an array, containing an array, containing the name of the link and the link itself, like so:

$links = array(array("Google","//google.co.uk"),array("Bing","//bing.co.uk"))
foreach ($links as $myurl){
foreach ($myurl as $url){
echo "<a href='".$url."'>".$myurl."</a>";
}};

I know the above doesn't work but if anyone can help with this problem, it is much appreciated.

解决方案

$links = array('Google' => 'www.google.com', 'Yahoo' => 'www.yahoo.com');

foreach($links as $k => $v) {
  echo '<a href="//' . $k . '">' . $v . '</a>'; 
}

As you can see I don't specify http or https, just // works on both! See: http://google-styleguide.googlecode.com/svn/trunk/htmlcssguide.xml

You can add links to $links with:

$links['stackoverflow'] = 'www.stackoverflow.com';

这篇关于制作一个单链接的PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆