Page 1 of 1

Add characters at the beggining of a textarea exported line

Posted: Mon Oct 30, 2006 8:14 pm
by ykarmi
is there any way to add a

Code: Select all

'
at the beginning of a line that came out of a textarea with php?
this is my code

Code: Select all

$myFile = "yourfile.js";
$information = $_POST['info'];
$fh = fopen($myFile, 'w') or die("can't open file");
$information = nl2br($information);
$information = str_replace("<br />","<br />'+", $information);
$insertinfo = "myText="."'<h5><center>".$information."</center></h5>'";
fwrite($fh, $insertinfo);
fclose($fh);
echo $information;
The code that the php exports in case there is more than one line in the textarea is this:

Code: Select all

myText='<h5><center>this<br />'+'
is a test</center></h5>'
All i need in order to make it work is the last ' to be at the beginning of the next line, like this:

Code: Select all

myText='<h5><center>this<br />'+
'is a test</center></h5>'
That way the js would be able to read it. Thank you very much in advanced,
Yuval :D

Posted: Mon Oct 30, 2006 8:24 pm
by feyd
addcslashes() would probably be of interest.

Posted: Mon Oct 30, 2006 8:43 pm
by ykarmi
the function addcslashes() does not help me due to the fact that i do not know what the user is going to type in. Unless i misunderstood it's purpose. An example that will apply to my code would make me very greatful

Solution

Posted: Mon Oct 30, 2006 9:39 pm
by ykarmi
I got help in a JavaScript forum.
The solution was extremely simple.
Apparently JavaScript ignores the line break if you add a "\" at the end of a line.
Because i was writing this code from PHP, it was important that i will add two "\"
like this "\\" so that PHP wouldn't "use" the first "\" and it won't get to the JS.
I had fun and i learned a lot from making this + now my client can update the news
on the website on his own using a very simple system the requires no coding - a system that I built =)
Thanks a million for trying to help, this forum is really nice. I am sorry for not introducing myself in the first place,
I was kind of in a rush. My name is Yuval, I'm 16 and I live in New Jersey. I moved from Israel a year ago and I started
programming PHP about two days ago, although i knew the syntax for a while. The thing I do the best is Flash, and design
in general. I'll see you guys around,
Thanks again for helping,
Yuval