Add characters at the beggining of a textarea exported line

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ykarmi
Forum Commoner
Posts: 35
Joined: Mon Oct 30, 2006 4:45 pm

Add characters at the beggining of a textarea exported line

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

addcslashes() would probably be of interest.
ykarmi
Forum Commoner
Posts: 35
Joined: Mon Oct 30, 2006 4:45 pm

Post 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
ykarmi
Forum Commoner
Posts: 35
Joined: Mon Oct 30, 2006 4:45 pm

Solution

Post 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
Post Reply