Jump to content

Problem with split


Xeon-YK

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...
Link to comment
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]
Link to comment
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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.