Exoon Posted September 2, 2010 Share Posted September 2, 2010 Hello Ive got a text area and i want to seperate each link that is placed inside the text area,. Is there a way using php exlode or somthing to reconise that the link has finished? Each of the links in the text area are on a new line. Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/212393-php-explode/ Share on other sites More sharing options...
wildteen88 Posted September 2, 2010 Share Posted September 2, 2010 If each link is on new line then you can explode on the new line character $links = explode("\n", $_POST['your_text_field_name']); Quote Link to comment https://forums.phpfreaks.com/topic/212393-php-explode/#findComment-1106608 Share on other sites More sharing options...
Exoon Posted September 2, 2010 Author Share Posted September 2, 2010 Hello, Just tried that but it only picks up the first link and ignores the rest. Quote Link to comment https://forums.phpfreaks.com/topic/212393-php-explode/#findComment-1106611 Share on other sites More sharing options...
wildteen88 Posted September 2, 2010 Share Posted September 2, 2010 Post your code here and some example links you're posting in your textarea Quote Link to comment https://forums.phpfreaks.com/topic/212393-php-explode/#findComment-1106614 Share on other sites More sharing options...
Exoon Posted September 2, 2010 Author Share Posted September 2, 2010 <?php if($_POST[newlinks]) { $newlinks = $_POST['newlinks']; $newlinks = explode(',', $newlinks); foreach ($newlinks as $newlink) { $new_number = substr("$newlink", -13, 4); echo "Updating Number: $new_number with the link $newlink <br />"; } } echo "<form method=\"POST\" action=\"mass_links.php\">"; echo "<br /> <strong>Enter the new links to try and replace old ones</strong> <br />"; echo "<textarea rows=\"16\" name=\"newlinks\" cols=\"84\"></textarea>"; ?> <input type="submit" value="Submit" name="B1"> That is using a commer which works but ide rather not have to type a commer after every link. Some example links: http://hotfile.com/dl/66308847/1976bc7/3517.rar.html http://hotfile.com/dl/66265394/24d9c85/4287.rar.html http://hotfile.com/dl/66263943/872c67d/4472.rar.html http://hotfile.com/dl/66264228/207bccd/4529.rar.html http://hotfile.com/dl/66303652/586fd94/4787.rar.html http://hotfile.com/dl/66307127/190e87c/5176.rar.html http://hotfile.com/dl/66262702/3b609e4/5180.rar.html Quote Link to comment https://forums.phpfreaks.com/topic/212393-php-explode/#findComment-1106615 Share on other sites More sharing options...
wildteen88 Posted September 2, 2010 Share Posted September 2, 2010 Use preg_split() instead $newlinks = preg_split('~\s+~s', $_POST['newlinks']); Quote Link to comment https://forums.phpfreaks.com/topic/212393-php-explode/#findComment-1106618 Share on other sites More sharing options...
Alex Posted September 2, 2010 Share Posted September 2, 2010 The reason it probably wasn't working before is because you were using single quotes. \n inside of single quotes is taken to be the literal characters "\" and "n" and not a line break character. Quote Link to comment https://forums.phpfreaks.com/topic/212393-php-explode/#findComment-1106628 Share on other sites More sharing options...
Exoon Posted September 2, 2010 Author Share Posted September 2, 2010 Thanks, that worked a treat. Do you know why it always does 1 more then it should ? Quote Link to comment https://forums.phpfreaks.com/topic/212393-php-explode/#findComment-1106635 Share on other sites More sharing options...
wildteen88 Posted September 3, 2010 Share Posted September 3, 2010 Do you know why it always does 1 more then it should ? How do you mean? Quote Link to comment https://forums.phpfreaks.com/topic/212393-php-explode/#findComment-1106749 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.