Jump to content

Archived

This topic is now archived and is closed to further replies.

Xeon-YK

Problem with split

Recommended Posts

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...

Share this post


Link to post
Share on other sites
Guest askjames01
try this;

[code]
<?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;
    }
}
?>
[/code]

Share this post


Link to post
Share on other sites
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:
[code]<?php $temp_str = split("\n", $str); ?>[/code]

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

Ken

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.