Hi guys, i have a content in one of phpmyadmin field screenshot 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:
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.
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 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:
<?php $text = 'text1\ntext2'; $xxx = explode('\n', $text); echo $xxx[0]; echo $xxx[1]; ?> Is the best solution for your problem
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: