[Basic] Move a content, from database, to a php file

Discussion in 'PHP' started by basketmen, Feb 14, 2012.

  1. #1
    Hi guys, i have a content in one of phpmyadmin field

    screenshot
    [​IMG]

    the content is like this, its have two lines :




    usually its called from a php file, using a variable, like this

    $xxx = explode("\r\n", $text);
    PHP:


    now i want to put the content, directly in the php file. This is working, to only put one line

    $xxx = explode("\r\n", "text1");
    PHP:


    But how is the right way to write both line? please help guys, i already tried these but no one works

    $xxx = explode("\r\n", "text1", "text2");
    PHP:


    $xxx = explode("\r\n", "text1, text2");
    PHP:

    
    $xxx = explode("\r\n", "text1");
    $xxx = explode("\r\n", "text2");
    
    PHP:


    $xxx = explode("\r\n", "text1" AND "text2");
    PHP:


    $xxx = explode("\r\n", "text1" . "text2");
    PHP:
     
    basketmen, Feb 14, 2012 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    If you're trying to write the data directly to a file with the line breaks included, don't explode it. Just use the $text variable and write it directly to the file.
     
    jestep, Feb 14, 2012 IP
  3. adityamenon

    adityamenon Peon

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #3
    Indeed, why are you trying to explode the text?
     
    adityamenon, Feb 14, 2012 IP
  4. Andre91

    Andre91 Peon

    Messages:
    197
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    0
    #4
    In your explode function, do not use double quotes (" "), but single quotes like I did. I don't know why, but double quotes doesn't work there in this case..... probably because of the character you're splitting by (\n)... I dunno :confused:

    But is this what you're looking for?

    
    <?php
    $text = 'text1\ntext2';           //This is how the data looks when pulled from the database, right?
    $xxx = explode('\n', $text);      //This splits the data by newline character (\n) and stores it in an array.
    
    echo $xxx[0];                     //This would output "text1"
    echo $xxx[1];                     //This would output "text2"
    ?>
    
    PHP:
     
    Andre91, Feb 15, 2012 IP
  5. spaculus

    spaculus Peon

    Messages:
    187
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    0
    #5
    <?php
    $text = 'text1\ntext2';
    $xxx = explode('\n', $text);

    echo $xxx[0];
    echo $xxx[1];
    ?>

    Is the best solution for your problem
     
    spaculus, Feb 16, 2012 IP
  6. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #6
    Not sure if I understood your question, but here is my take:

    
    // Take results from DB (text1, text2)
    $xxx = explode("\r\n", $text);
    
    // Add your injections
    $xxx[] = 'text3';
    $xxx[] = 'text4';
    //....
    
    PHP:
     
    ThePHPMaster, Feb 16, 2012 IP