Jump to content


Photo

Problem with split


  • Please log in to reply
2 replies to this topic

#1 Xeon-YK

Xeon-YK
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 04 May 2006 - 05:49 AM

i have a problem with split.
i want to ask how if i want split the string with enter character

example :

i have string :

rudy 10 male
eric 12 male
john 13 male

when i split with enter character i will become three part
1. rudy 10 male
2. eric 12 male
3. john 13 male

i have try with this $temp_str = split('\n', $str);

but i didn't work, the result is split with n character.

how to solve this problem, thank...

#2 Guest_askjames01_*

Guest_askjames01_*
  • Guests

Posted 04 May 2006 - 07:00 AM

try this;

<?php
$arr = array(10=>"rudy 10 male", 12=>"eric 12 male", 13=>"john 13 male");

$j=1;
for ($i = 10; $i <= 13; $i++) {
    if($i != 11) {
        echo $j." {$arr[$i]}"."<br/>";
        ++$j;
    }
}
?>


#3 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 04 May 2006 - 11:39 AM

The problem you're seeing is that you used single quotes around the newline character instead of double quotes. Any string inside single quotes is treated literaly -- no expansions.

Try this:
<?php $temp_str = split("\n", $str); ?>

For askjames01: you gave the OP a solution to a problem he didn't ask about and my not have.

Ken




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users