I have this... <?php $links = explode("\n", $_POST['links']); foreach ($links as $links) { echo '[PART="NUM"]'.$links.'[/PART] <br />'; } ?> PHP: Where it says NUM I want the number of its position in the array. So if I fed this to this script: http://www.google.com http://www.yahoo.com http://www.ask.com Code (markup): The script would then output: [PART="1"]http://www.google.com[/PART] [PART="2"]http://www.yahoo.com[/PART] [PART="3"]http://www.ask.com[/PART] Code (markup): How would I go about doing this?
<?php $links = explode("\n", $_POST['links']); $num=0; foreach ($links as $links) { $num++; echo '[PART="'.$num.'"]'.$links.'[/PART] <br />'; } ?> PHP:
$links= “http://www.google.com;http://www.yahoo.com;http://www.ask.com"; $websites= explode(â€;â€, $links); $websites= Array ( [0] => http://www.google.com [1] => http://www.yahoo.com [2] => http://www.ask.com ) echo $websites[0]; echo $websites[1]; echo $websites[2]; PHP: You may be running into a slight issue with the http:// part as this may be seen as a PHP comment. You can try leaving that part out and doing something like this: echo "http://$websites[0]"; echo "http://$websites[1]"; echo "http://$websites[2]"; PHP:
^ Do you understand what a rubbish reply that was? Seriously man, if you don't know how to code in PHP, stay away instead of offering useless solutions.
^ Why? Whats wrong with it? There are a ton of ways to end up at the same place in the end. That's one solution.
<?php $links = <<< links http://www.google.com http://www.yahoo.com http://www.ask.com links; /* Gen */ $i = 0 or $links = explode("\n", str_replace("\r", '', $links)); foreach ( $links as $link ) echo '[PART=' . ++$i . ']' . $link . '[/PART]' . PHP_EOL; PHP:
I'm gonna go with the variable that can already be passed through a foreach() loop instead of creating my own. Really, though, InputProductions, your reply was just not very helpful. lol <?php $links = explode("\n", $_POST['links']); foreach ($links as $id=>$links) { echo '[PART="'.(++$id).'"]'.$links.'[/PART] <br />'; } ?> PHP:
Thanks for all your replies. I found this was the best solution: $count = count($links); for($i=0;$i<$count;$i++) { echo '[PART="'.($i+1).'"]'.$links[$i].'[/PART] <br />'; } PHP: