idontknowphp Posted December 7, 2011 Share Posted December 7, 2011 This is what I have now...im getting an undefined offset error, but $i should be set....unless my loop is a fail? I don't know... <form action="<?php echo $_SERVER['PHP_SELF']; ?>"method="post"> <label>URLs delimited by a COMMA</label> <textarea name="urls"></textarea> <input name="submit" type="submit" value="Submit" /> </form> <?php if (isset($_POST['submit'])) { $urls = trim($_POST['urls']); // remove white space from user input $arr = explode( ",", $urls); // convert the input into an array $count = count($arr); // count the number of items in the array for ($i = 0; $i <= $count; $i++) { // setup the loop to stop iteration when $count is met echo '<pre><a href="' . $arr[$i] . '>' . $arr[$i] . '</a></pre>'; // Hopefully echo the link list back if all goes well... } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/252639-help-using-data-from-an-exploded-array-this-should-be-so-simple-for-anyone-else/ Share on other sites More sharing options...
btellez Posted December 7, 2011 Share Posted December 7, 2011 From what I can tell your just going one too far into your array. Undefined offset refers to your array. eg: Array with 6 elements, has elements numbered 0-5; /* change the comparison to continue while $i < $count, since the index is 1 less than the count...so...*/ for ($i = 0; $i <$count; $i++) { // setup the loop to stop iteration when $count is met echo '<pre><a href="' . $arr[$i] . '>' . $arr[$i] . '</a></pre>'; // Hopefully echo the link list back if all goes well... } Quote Link to comment https://forums.phpfreaks.com/topic/252639-help-using-data-from-an-exploded-array-this-should-be-so-simple-for-anyone-else/#findComment-1295172 Share on other sites More sharing options...
idontknowphp Posted December 7, 2011 Author Share Posted December 7, 2011 While that did solve the error, not all of the items are being echoed back...I put in 9 items and got back 3 Seriously thanks for the quick response though...I really appreciate it. Quote Link to comment https://forums.phpfreaks.com/topic/252639-help-using-data-from-an-exploded-array-this-should-be-so-simple-for-anyone-else/#findComment-1295182 Share on other sites More sharing options...
SergeiSS Posted December 7, 2011 Share Posted December 7, 2011 You would better use foreach loop to iterate through the array $arr. You will automatically get array elements and (if you need) array indexes. Quote Link to comment https://forums.phpfreaks.com/topic/252639-help-using-data-from-an-exploded-array-this-should-be-so-simple-for-anyone-else/#findComment-1295183 Share on other sites More sharing options...
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.