Xeon-YK Posted May 4, 2006 Share Posted May 4, 2006 i have a problem with split.i want to ask how if i want split the string with enter characterexample : i have string : rudy 10 maleeric 12 malejohn 13 malewhen i split with enter character i will become three part1. rudy 10 male2. eric 12 male3. john 13 malei 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 https://forums.phpfreaks.com/topic/9036-problem-with-split/ Share on other sites More sharing options...
Guest askjames01 Posted May 4, 2006 Share Posted May 4, 2006 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 https://forums.phpfreaks.com/topic/9036-problem-with-split/#findComment-33223 Share on other sites More sharing options...
kenrbnsn Posted May 4, 2006 Share Posted May 4, 2006 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 https://forums.phpfreaks.com/topic/9036-problem-with-split/#findComment-33256 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.