Author Topic: php explode  (Read 465 times)

0 Members and 1 Guest are viewing this topic.

Offline ExoonTopic starter

  • Enthusiast
  • Posts: 81
    • View Profile
php explode
« on: September 02, 2010, 04:02:50 PM »
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.

Offline wildteen88

  • Guru
  • 'Insane!'
  • *
  • Posts: 12,021
  • Gender: Male
    • View Profile
Re: php explode
« Reply #1 on: September 02, 2010, 04:05:49 PM »
If each link is on new line then you can explode on the new line character
$links explode("\n"$_POST['your_text_field_name']);
« Last Edit: September 02, 2010, 04:06:22 PM by wildteen88 »

Offline ExoonTopic starter

  • Enthusiast
  • Posts: 81
    • View Profile
Re: php explode
« Reply #2 on: September 02, 2010, 04:11:16 PM »
Hello,

Just tried that but it only picks up the first link and ignores the rest.

Offline wildteen88

  • Guru
  • 'Insane!'
  • *
  • Posts: 12,021
  • Gender: Male
    • View Profile
Re: php explode
« Reply #3 on: September 02, 2010, 04:16:00 PM »
Post your code here and some example links you're posting in your textarea

Offline ExoonTopic starter

  • Enthusiast
  • Posts: 81
    • View Profile
Re: php explode
« Reply #4 on: September 02, 2010, 04:18:42 PM »

<?php

if($_POST[newlinks]) {

$newlinks $_POST['newlinks'];

$newlinks explode(','$newlinks);

    foreach (
$newlinks as $newlink) {
      
$new_number substr("$newlink", -134);    
      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:

Quote
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

Offline wildteen88

  • Guru
  • 'Insane!'
  • *
  • Posts: 12,021
  • Gender: Male
    • View Profile
Re: php explode
« Reply #5 on: September 02, 2010, 04:25:11 PM »
Use preg_split() instead
    $newlinks preg_split('~\s+~s'$_POST['newlinks']);

Offline Alex

  • Global Moderator
  • Addict
  • *
  • Posts: 2,487
  • Gender: Male
  • < 1 billion
    • View Profile
Re: php explode
« Reply #6 on: September 02, 2010, 04:38:43 PM »
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.
:anim_rules: Read the rules, :rtfm: and don't forget to use [code] / [php] tags!


Offline ExoonTopic starter

  • Enthusiast
  • Posts: 81
    • View Profile
Re: php explode
« Reply #7 on: September 02, 2010, 05:01:52 PM »
Thanks, that worked a treat. Do you know why it always does 1 more then it should ?

Offline wildteen88

  • Guru
  • 'Insane!'
  • *
  • Posts: 12,021
  • Gender: Male
    • View Profile
Re: php explode
« Reply #8 on: September 03, 2010, 05:22:59 AM »
Do you know why it always does 1 more then it should ?
How do you mean?