Exoon Posted November 19, 2011 Share Posted November 19, 2011 Hi, Im trying to make a script to mass update a load of links in my database but im stuck on the basics, How can i detect a new line in a text area? Anyone know why this dosen't work? <?php if($_POST[newlinks]) { $newlinks = preg_split("\n", ($_POST['newlinks'])); $i = 1; foreach ($newlinks as $newlink) { echo "$i - $newlink <br />"; $i++; } } else { echo "<form method=\"POST\" action=\"changehost.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>"; echo "<input type=\"submit\" value=\"Submit\" name=\"B1\">"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/251445-detect-new-line-in-text-area/ Share on other sites More sharing options...
mikesta707 Posted November 19, 2011 Share Posted November 19, 2011 Why are you using preg_replace? str_replace seems like it would work perfectly fine here. $newlinks = str_replace("\n", "", $_POST['newlinks']);//replace all newlines with empty strings, thus removing them from the string Quote Link to comment https://forums.phpfreaks.com/topic/251445-detect-new-line-in-text-area/#findComment-1289586 Share on other sites More sharing options...
Exoon Posted November 19, 2011 Author Share Posted November 19, 2011 Im using preg_split not replace. Im going to be entering 1000s of links i want all of them split up individually so i can try and replace each link 1 by 1 Quote Link to comment https://forums.phpfreaks.com/topic/251445-detect-new-line-in-text-area/#findComment-1289587 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.