So I have this snippet which gets my input from textarea named "cdet" & opens "index.php" & finds string "details" & replace it with my input-
if(ISSET($_REQUEST["sub"])){
$cdet=$_REQUEST["cdet"];
$fname = "index.php";
$fhandle = fopen($fname,"r");
$content = fread($fhandle,filesize($fname));
$content = str_replace("details", $cdet, $content);
$fhandle = fopen($fname,"w");
fwrite($fhandle,$content);
}
fclose($fhandle);
& this is the part in "index.php" where the string "details" is-
<p class="wNote">details</p>
What I want is that if a line break/new line occurs in the input, I would end the current
& invoke a new one for the new line...
e.g- if input is
Hello there.. What are you doing here?
then details should be replaced like-
<p class="wNote">Hello there..</p>
<p class="wNote">What are you doing here?</p>
First, you can load file the easier way, with file_get_contents()
function:
http://php.net/manual/en/function.file-get-contents.php
Then, after you get that $cdet field value use explode()
function to split it by " " sign (new row). That way you'll get an array that contains rows of text.
Then iterate trough that array (with foreach()
) and for every row add that '<p class="wNote">
', then row content and then '</p>
'.
At end you can't just replace that 'details' words with your result, but you must replace whole '<p class="wNote">details</p>
' with your output, because you can have more than one row now.