SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict lmasi02's Avatar
    Join Date
    Aug 2004
    Location
    Zambia
    Posts
    257
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    separator problem in explode

    i have a code herebelow but could find a suitable separot for the line break in the textarea. Any help
    PHP Code:
    <?php echo 
    if(isset(
    $_POST['submit'])){
        
    $data=explode('',$_POST['data']);# trouble getting the separetor for the line break on inthe textarea
        
    for($i=0$i<count($data);$i++){
            
    $sq"select allocate.amount from allocate inner join employee on employee.emp_id= allocate.emp_id ";
            
    $sq.="where phone='$data[$i]'";
            
    $r=mysql_fetch_array(mysql_query($sq));
            
    $sum+=$r['amount']; # Adds up all the failed transction
        
    }
    }
     
    ?>

    <form action="" method="post">
    <textarea name="data" cols="30" rows="5"></textarea><br>
    <input name="submit" type="submit" value="submit"></form>
    Last edited by lmasi02; Feb 11, 2009 at 07:27.
    Power of Knowledge

  2. #2
    Web Professional
    Join Date
    Oct 2008
    Location
    London
    Posts
    862
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Depending on the user's system it will be either "\r", "\n", or "\r\n":
    PHP Code:
        /* replace Windows style newlines (carriage return followed
         * by linefeed) and Mac style newlines (carriage return)
         * with *nix style newlines (linefeed)
         */
        
    $_POST['data'] = str_replace(array("\r\n""\r"), "\n"$_POST['data']);
        
    $data=explode("\n",$_POST['data']); 

  3. #3
    SitePoint Addict lmasi02's Avatar
    Join Date
    Aug 2004
    Location
    Zambia
    Posts
    257
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thnx, ti tried this but the result are in one line
    PHP Code:
    <?php 
    if(isset($_POST['submit'])){
        
    $dat str_replace(array("\r\n""\r"), "\n"$_POST['data']);
        
    $data=explode('\n',$dat);# trouble getting the separetor for the line break on inthe textarea
        
    for($i=0$i<count($data);$i++){
            echo 
    $data[$i]."<br>";
            
        }
    }
     
    ?>

    <form action="" method="post">
    <textarea name="data" cols="30" rows="5"></textarea><br>
    <input name="submit" type="submit" value="submit"></form>
    Power of Knowledge

  4. #4
    Web Professional
    Join Date
    Oct 2008
    Location
    London
    Posts
    862
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
        $data=explode("\n",$dat);# trouble getting the separetor for the line break on inthe textarea
                      
    ^  ^ 
    If you use single quotes then the \n is treated as a literal string rather than newline character.

  5. #5
    SitePoint Addict lmasi02's Avatar
    Join Date
    Aug 2004
    Location
    Zambia
    Posts
    257
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thnx Paul, You are the Man
    Power of Knowledge


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •