Headphone Posted July 24, 2012 Report Share Posted July 24, 2012 Ai galera como faço um script assim:<?php$link = "http://www.google.com.br/,http://www.yahoo.com.br,http://www.big.com.br";$site = "Google,Yahoo,Big";?>ou<?php$link = "http://www.google.com.br/,http://www.yahoo.com.br,http://www.big.com.br";$site = "Google,Yahoo,Big, MSN";?>Resultado seria sair assimPrimeiro:<ul><li><a href="http://www.google.com.br">Google</a></li><li><a href="http://www.yahoo.com.br">Yahoo</a></li><li><a href="http://www.big.com.br">Big</a></li></ul>Caso seja com a segunda opção, aparecia assim<ul><li><a href="http://www.google.com.br">Google</a></li><li><a href="http://www.yahoo.com.br">Yahoo</a></li><li><a href="http://www.big.com.br">Big</a></li><li>MSN</li></ul> Quote Link to comment Share on other sites More sharing options...
0 Headphone Posted July 24, 2012 Author Report Share Posted July 24, 2012 Consegui amores Quote Link to comment Share on other sites More sharing options...
0 dinohills Posted July 24, 2012 Report Share Posted July 24, 2012 Conseguiu ? Posta ai pro pessoal que vier procurar ver como você fez tambem. Assim outras pessoas podem consultar e ter ideias. Quote Link to comment Share on other sites More sharing options...
0 Headphone Posted July 24, 2012 Author Report Share Posted July 24, 2012 Bom, consegui e não consegui. :Dboa parte já consegui, agora só falta por o link na linha dele.<?php $link = "http://www.google.com.br/,http://www.yahoo.com.br,http://www.big.com.br"; $site = "Google,Yahoo,Big, MSN"; $string = explode(",", $site); echo '<ul>'; foreach ($string as $key => $val){ echo '<li><a href="">'.trim($val).'</a></li>'; } echo '</ul>'; ?>Quem consegue resolver para mim? Quote Link to comment Share on other sites More sharing options...
0 dinohills Posted July 24, 2012 Report Share Posted July 24, 2012 Aqui cara use array é mais facil eu acho pelo menos<?php $link = array("http://www.google.com.br/","http://www.yahoo.com.br","http://www.big.com.br"); $site = array("Google","Yahoo","Big"); echo "<ul>"; for($i=0;$i< count($link);$i++){ echo "<li><a href=\"$link[$i]\">$site[$i]</a></li>"; } echo "</ul>"; ?>Agora uma coisa, porque você quer dexar o MSN sem link ? Quote Link to comment Share on other sites More sharing options...
0 Headphone Posted July 24, 2012 Author Report Share Posted July 24, 2012 Aqui cara use array é mais facil eu acho pelo menos<?php $link = array("http://www.google.com.br/","http://www.yahoo.com.br","http://www.big.com.br"); $site = array("Google","Yahoo","Big"); echo "<ul>"; for($i=0;$i< count($link);$i++){ echo "<li><a href=\"$link[$i]\">$site[$i]</a></li>"; } echo "</ul>"; ?> Agora uma coisa, porque você quer dexar o MSN sem link ? cara eu queria que fica-se assim: <?php $link = "http://www.google.com.br/,http://www.yahoo.com.br,http://www.big.com.br; $site = "Google,Yahoo,Big"; echo "<ul>"; for($i=0;$i< count($link);$i++){ echo "<li><a href=\"$link[$i]\">$site[$i]</a></li>"; } echo "</ul>"; ?>sem uso de ARRAY, porque o sistema que estou a usar esse sistema não daria certo usar com array Quote Link to comment Share on other sites More sharing options...
0 dinohills Posted July 24, 2012 Report Share Posted July 24, 2012 E assim ? <?php $link = "http://www.google.com.br/,http://www.yahoo.com.br,http://www.big.com.br"; $site = "Google,Yahoo,Big"; $links = explode(',', $link); $sites = explode(',', $site); echo "<ul>"; for($i=0;$i< count($links);$i++){ echo "<li><a href=\"$links[$i]\">$sites[$i]</a></li>"; } echo "</ul>"; ?> Quote Link to comment Share on other sites More sharing options...
0 Headphone Posted July 24, 2012 Author Report Share Posted July 24, 2012 E assim ? <?php $link = "http://www.google.com.br/,http://www.yahoo.com.br,http://www.big.com.br"; $site = "Google,Yahoo,Big"; $links = explode(',', $link); $sites = explode(',', $site); echo "<ul>"; for($i=0;$i< count($links);$i++){ echo "<li><a href=\"$links[$i]\">$sites[$i]</a></li>"; } echo "</ul>"; ?>vlw cara eu te amo Quote Link to comment Share on other sites More sharing options...
0 dinohills Posted July 24, 2012 Report Share Posted July 24, 2012 (edited) rsrsr não precisa amar, só agradecendo já ta bom :PSó explica o porque você não poderia usar array ? Edited July 24, 2012 by dinohills Quote Link to comment Share on other sites More sharing options...
0 Headphone Posted July 24, 2012 Author Report Share Posted July 24, 2012 rsrsr não precisa amar, só agradecendo já ta bom :PSó explica o porque você não poderia usar array ?Porque essa função irei usar em um template wordpress (campos personalisado)ai não iria funcionar com array. Quote Link to comment Share on other sites More sharing options...
0 Willian Gustavo Veiga Posted July 25, 2012 Report Share Posted July 25, 2012 Mas com o explode você acaba usando arrays :)Um abraço. Quote Link to comment Share on other sites More sharing options...
0 fiote Posted July 25, 2012 Report Share Posted July 25, 2012 William, o problema parece ser o input. As variáveis $link e $site dele são provavelmente um campo de _POST ou _GET, logo acredito que não tem como elas serem originalmente vetores. Quote Link to comment Share on other sites More sharing options...
Question
Headphone
Ai galera como faço um script assim:
<?php
$link = "http://www.google.com.br/,http://www.yahoo.com.br,http://www.big.com.br";
$site = "Google,Yahoo,Big";
?>
ou
<?php
$link = "http://www.google.com.br/,http://www.yahoo.com.br,http://www.big.com.br";
$site = "Google,Yahoo,Big, MSN";
?>
Resultado seria sair assim
Primeiro:
<ul>
<li><a href="http://www.google.com.br">Google</a></li>
<li><a href="http://www.yahoo.com.br">Yahoo</a></li>
<li><a href="http://www.big.com.br">Big</a></li>
</ul>
Caso seja com a segunda opção, aparecia assim
<ul>
<li><a href="http://www.google.com.br">Google</a></li>
<li><a href="http://www.yahoo.com.br">Yahoo</a></li>
<li><a href="http://www.big.com.br">Big</a></li>
<li>MSN</li>
</ul>
Link to comment
Share on other sites
11 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.