Werte aus einem Array

br3doxx

Mitglied
Hallo, wie bekomme ich die erstellten Links in eine Variable?

PHP:
$test = "test.de,test.com,test.net";
$links = preg_split("/,/", $test);

foreach($links as $link)
  {
	 $link_n = "<a href=\"http://".$link."\">".$link."</a>";
  }
 
Hey br3doxx,
oder vielleicht so ?
PHP:
<?php 
$test = "test.de,test.com,test.net";
$links = explode(",", $test);
$link_n = "";
 
foreach($links as $link)
{
    $link_n .= "<a href=\"http://".$link."\">".$link."</a><br />\n";
}  
 
echo $link_n;  
?>

MfG OloX
 
Als Array?
PHP:
$link_n[] = "<a href=\"http://".$link."\">".$link."</a>";

Danke schonmal. Habs auch bissel einfach beschrieben.

Ich möchte im Endeffekt die Links in einer Tabelle anzeigen lassen:
HTML:
<table>
	<tr>
		<td>Titel</td>
		<td>Datum</td>
	</tr>
	<tr>
		<td colspan="2">HIER DIE LINKS</td>
	</tr>
</table>
 
Hey br3doxx,
oder vielleicht so ?
PHP:
<?php 
$test = "test.de,test.com,test.net";
$links = explode(",", $test);
$link_n = "";
 
foreach($links as $link)
{
    $link_n .= "<a href=\"http://".$link."\">".$link."</a><br />\n";
}  
 
echo $link_n;  
?>

MfG OloX

Ja, so wollte ich es, geht aber nicht, da nur der letzte Wert angezeigt wird.
 
Mit dem Code werden die Links einfach untereinnander ausgegeben ;)
Mit dem Code:
PHP:
<?php 
$test = "test.de,test.com,test.net";
$links = explode(",", $test);
$link_n = "";
 
foreach($links as $link)
{
    $link_n .= "<a href=\"http://".$link."\">".$link."</a><br />\n";
}  
 
echo $link_n;  
?>
kommt bei mir
HTML:
<a href="http://test.net">test.net</a>
als Ausgabe

Ich möchte im Endeffekt die Links in einer Tabelle anzeigen lassen:
HTML:
<table>
	<tr>
		<td>Titel</td>
		<td>Datum</td>
	</tr>
	<tr>
		<td colspan="2">HIER DIE LINKS</td>
	</tr>
</table>
 
Das ist aber sehr komisch :-(
HTML:
<a href="http://test.de">test.de</a><br />
<a href="http://test.com">test.com</a><br />
<a href="http://test.net">test.net</a><br />
So hat es bei mir ausgesehen ;)

PHP:
<?php 
$test = "test.de,test.com,test.net";
$links = explode(",", $test);
$link_n = "";
 
foreach($links as $link)
{
    $link_n .= "<tr>\n<td><a href=\"http://".$link."\">".$link."</a></td>\n<td>&nbsp;</td></tr>\n";
}  
?>
<table border="1" cellpadding="4" cellspacing="0">
  <tr>
    <th scope="col">Titel</th>
    <th scope="col">Datum</th>
  </tr>
	<?php echo $link_n; ?> 
</table>
 
Dann mach das ganze doch mal wie folgt:

PHP:
<table>
<?php 
$test = "test.de,test.com,test.net";
$links = explode(",", $test);
$link_n = "";
 
foreach($links as $link)
{
    $link_n = "<a href=\"http://".$link."\">".$link."</a><br />\n";
echo"
	<tr>
		<td>Titel</td>
		<td>Datum</td>
	</tr>
	<tr>
		<td colspan='2'>$link_n</td>
	</tr>";
}
?>
</table>
 

Neue Beiträge

Zurück