I need one perg_replace function to replace "\r\n" with "<br>" except "\r\n" that beetween [textarea] and [/textarea]
is this impossible ?
Printable View
I need one perg_replace function to replace "\r\n" with "<br>" except "\r\n" that beetween [textarea] and [/textarea]
is this impossible ?
for you????? no, it is not possible
M.R scouttQuote:
Originally posted by scoutt
for you????? no, it is not possible
What about for others ?
for others, they understand php
your funny........ :D
All others understand it except me !!??!! I understand it also but I want to sure of my answer so help me to sure of that ..
so why not post what you have and then allow us to help you from that?
M.R cpradio.
that is all I have
$html = preg_replace("something here", "also something here", $html);
I think that it's right code but the problem that i do not know this (something)
is that may help me ?
http://www.php.net/manual/en/function.nl2br.php
I think you are confused on how you should go about solving your problem.
Maybe if you provide us an example of how the text between the two <textarea></textarea> tags is being generated, we can find a solution for you.
Unless you're doing something I haven't thought of, I'm pretty sure there's a way around using a preg_replace. :confused:
also, I meant for you to show us what you have tested as your preg_replace expressions. We have given you plenty of examples in the past to where you should be getting the hang of this now.
the problem that I have text area that I insert some lines in it for exablem I write this lines inside this textarea and after that I press submit button:
--------------------------------------
that is a new php code
open NotePad and write it
[textarea]
<?
echo "A";
echo "B";
?>
[/textarea]
---------------------------------------
I want to echo text that inside this textarea in another page so I replace new line with "<BR>" so and also replace [textarea] with <textarea> and [/textarea] with </textarea> because I want to display php code that I write above inside text area.
when I do that I found output like that
--------------------------------------------------
that is a new php code
open NotePad and write it
and out put inside textarea like that
______________
<? <BR>
echo "A"; <BR>
echo "B"; <BR>
?> <BR>
______________
so the problem how can I get rid of <br> that inside this textarea.
please help me to do that and that will be the last question in preg_replace function .. Thanks
dont do that stepQuote:
I want to echo text that inside this textarea in another page so I replace new line with "<BR>"
if I do not do this step this 2 lines:
_____________________
that is a new php code
open NotePad and write it
_____________________
will become one line .. like that
_________________________________________
that is a new php code open NotePad and write it
_________________________________________
so use this as your echo:
echo nl2br($text);
That way you do not have to modify its contents
When I used
echo nl2br($text);
also it give me the same result
That it is the text inside textarea
______________
<? <BR >
echo "A"; <BR >
echo "B"; <BR >
?> <BR >
______________
to solve this problem I need replace_preg function to replace new line with "<br>" except new line that between [textarea] and [/textarea]
NO!!
You use that echo for when you need to print it to the page, you only use:
when outputing in the <textarea>PHP Code:echo $text;
Relly that will not solve the problem. if you do not replace new line with <BR> all lines will show in on line .. if you replaced it the <br> will show inside textarea.
a textarea reads \n\r as new lines. HTML does not! Try it and see for yourself
a textarea reads \n\r as new lines. HTML does not! Try it and see for yourself.
That is true. but when I replace \r\n with <br> the \r\n inside textarea changed to <BR>
DONT REPLACE IT!!
PHP Code:// To Screen
echo nl2br($text);
// To textarea
echo "<textarea>$text</textarea>";
I must replace it. the problem that I save text like that in database in one cell :
____________________
that is a new php code
open NotePad and write it
[textarea]
<?
echo "A";
echo "B";
?>
[/textarea]
____________________
so I want get it and replace \r\n with "<BR>"
so my question . How replce \r\n with "<BR>" except any \r\n that between [textarea] and [/textarea]
prok...
can you just post the section of code that you are doing this replacing in, and we'll make it work for you.
maybe by actually seeing the code you'll understand what we mean?
hmmm...is this all user typed?Quote:
Originally posted by prokhaled
I must replace it. the problem that I save text like that in database in one cell :
____________________
that is a new php code
open NotePad and write it
[textarea]
<?
echo "A";
echo "B";
?>
[/textarea]
____________________
so I want get it and replace \r\n with "<BR>"
so my question . How replce \r\n with "<BR>" except any \r\n that between [textarea] and [/textarea]
boy you have lost me so much.
what is going in the database? if you have a textarea and then you send the form, what OTHER text needs to be replaced? when the text from the textarea goes into the DB then don't replace the \r\n with anything.
there is no other text. the form is sending only the textarea to DB.
I don't understand preg_replaces very well, but I think it would be easier to replace all the \r\n with <br> then replace them within the [textarea] bits. Kinda seems odd. But maybe someone can help you with it.
But now I understand why you can't just echo it seperately.
Try working with this code that I posted in one of your previous threads. You should be able to modify it to work:
PHP Code:<?php
$test1 = "Hi how Are you [E] A A A [/E] Fine A A [E] A any text A [/E]";
echo "Test1 = " . $test1 . "<br>After Function, = " . convert($test1) . "<br><br>";
//THE FUNCTION:
function convert($text) {
if (!strpos($text, "[E]") === false) {
do {
$pos = strpos($text, "[E]", $epos);
$ntext .= str_replace("A", "B", substr($text, $epos, $pos - $epos)); // . "<br>";
$epos = strpos($text, "[/E]", $pos) + 4;
$ntext .= substr($text, $pos, $epos - $pos);
} while (!strpos($text, "[E]", $epos) === false);
} else {
$ntext = str_replace("A", "B", $text);
}
return $ntext;
}
?>
M.R scoutt And M.R Hebo , that is the code that I use.
Code:$SubjectText=$Row[SubjectText]
$SubjectText = str_replace("", "</textarea>", $SubjectText);
Code:
", "<textarea type=text name=ms rows=8 cols=70 wrap='virtual'>", $SubjectText);
$SubjectText = str_replace("
$SubjectText = str_replace("\r\n", " <BR> ",$SubjectText);
I need some thing like [code] that use in forums to write code(s) but I want to disply this code inside textarea.
Thanks.
M.R Hobo. your code may work without problem but what I need to use short code. I think that preg_replace can do that but the problem that I do not know how can I use it.
if that is all you are doing then take thePHP Code:$SubjectText=$Row[SubjectText]
$SubjectText = str_replace("[CODE]", "<textarea type=text name=ms rows=8 cols=70 wrap='virtual'>", $SubjectText);
$SubjectText = str_replace("[/ CODE]", "</textarea>", $SubjectText);
$SubjectText = str_replace("\r\n", " <BR> ",$SubjectText);
$SubjectText = str_replace("\r\n", " <BR> ",$SubjectText);
OUT!!!!! you don't need it.
do it like this.....
PHP Code:$SubjectText=$Row[SubjectText]
$SubjectText = str_replace("[CODE]", "<textarea type=text name=ms rows=8 cols=70 wrap='virtual'>", $SubjectText);
$SubjectText = str_replace("[/ CODE]", "</textarea>", $SubjectText);
I try you code but it give me the same problem. test it youself
if $row[Subjecttext]= for exam:
--------------------------------------
that is a new php code
open NotePad and write it
[textarea]
<?
echo "A";
echo "B";
?>
[/textarea]
---------------------------------------
I want to put "<br>" here only:
that is a new php code <br> open NotePad and write it.
but for sorry I found <br> writen with code inside textarea after replace \r\n with <br>
for example I see that inside <textarea> after replacing.
___________________
echo "A"; <br> echo "B";
___________________
why do you keep saying open notepad? where are you getting this info from? where is
that is a new php code
open NotePad and write it
[textarea]
<?
echo "A";
echo "B";
?>
[/textarea]
coming from????
I do not understand .. that is for example.
from a database, I believe?Quote:
Originally posted by scoutt
why do you keep saying open notepad? where are you getting this info from? where is
that is a new php code
open NotePad and write it
[textarea]
<?
echo "A";
echo "B";
?>
[/textarea]
coming from????
that is what I am thinking. if it is from a database then when you insert that into the database don't replace the \r\n with <br>'s duh.
for an example means you don't know what the heck you are doing as you are just asking for code. well for an example pay attention to what we say and you might get farther.
chill out :rolleyes:Quote:
Originally posted by scoutt
that is what I am thinking. if it is from a database then when you insert that into the database don't replace the \r\n with <br>'s duh.
for an example means you don't know what the heck you are doing as you are just asking for code. well for an example pay attention to what we say and you might get farther.
Although I'm not sure, I think the database entries could be user input. If so, then he has no control over it.
Keep your thumb out of your ass, scoutt.
up yours Hobo
_________________________
that is a new php code
open NotePad and write it
[textarea]
<?
echo "A";
echo "B";
?>
[/textarea]
_________________________
yes, this text come from database.
how is it going into the DB
by any user.
any user can add subject like that . there is form contain textarea and submit button, and any user can add subject to database like this this forum.
That's great...so why don't you write it then? I'm not going to write 42 solutions for you so you can pick the one you like the best.Quote:
Originally posted by prokhaled
M.R Hobo. your code may work without problem but what I need to use short code. I think that preg_replace can do that but the problem that I do not know how can I use it.
I don't swing that way, man.Quote:
Originally posted by scoutt
up yours Hobo
then if you are entring it in the DB don't do a str_replace. just enter the textarea contents in the DB just like it sits.Quote:
Originally posted by prokhaled
by any user.
any user can add subject like that . there is form contain textarea and submit button, and any user can add subject to database like this this forum.
and what when I want to show this subject ?
That mean that there is no any way(code) to replace \r\n with <br> except \r\n that between [textarea] and [/text area] ?
no no no
listen carefully. Read carefully.....
the user enters text in the textarea. then submit it to the database. when you take them out of the DB DON'T use a str_replace on the contents of the textbox. so whatever the users enters in the textbox will get added to the DB without and replacing so when you echo them out of the DB it will look normal and be on 1 line.
I hope you don't have *everything* going into 1 DB column.
all text go to one cell (1 DB column)
so you have all the text the user puts in the form going to 1 column? how many others are going. show us the form please.
it's normal form contain :
1- NAME :
2 - PASSWORD
3- Subject
it's in my new forum (VBZooM Forum) .. Near I will make english copy of it until yo can download it and tell me your opinon ?
It's HERE:
http://vbzoom.com/forums
hmmm it is all backwards from this forum. so let me get this straight. you want to take the reply and insert it into the DB?
so you have ReplyText the only thing going beside the name and password?
if that is correct them how are you entering ReplyText into the DB. what is the code you have to enter things to DB.
I have reply text . I use this code to insert reply to DB
PHP Code:
$Sql = "INSERT INTO Reply (MainID,SubjectID,ReplyTitle,ReplyText,Replier,Icon,ReplyDate,ReplyTime,Attach,DownloadNo,ActiveUrl,ShowSignature) VALUES ('$MainID','$SubjectID','$ReplyTitle','$ReplyText','$Replier','$Icon','$ReplyDate','$ReplyTime','$Attach','0','$ActiveUrl','$ShowSignature')";
$Result = mysql_query($Sql);
and that is it? you don't replace <textarea> with [textarea] or anything? then what are you worried about? if you put anything in the textarea in the DB and don't replace anything it will not add any <br>'s inplace of the \r\n
user can Insert ReplyText like that
I want when I show this reply disply:PHP Code:Good Code
Write It now
[CODES]
Any
Code
Here
[/CODES]
_________
Any
Code
Here
__________
inside textarea not between table and not between two lines <HR> like this forum .. I want to disply code inside textarea after that.. I hope you can unserstand me.
I am so lost. you say they enter text in a text box. it then goes to the DB and when you take it out of the DB you want to show the text on different lines like so
Any
Code
Here
in a <textarea> or on the page like you are reading this now?
GOOD.
Yes that is what I mean. you are right.
ok so if they add tags like [code] then you want to make the other text (outside the [code] tags) to be one line? and everything inside the [code] tags to have a line break, right?
I want to make Every lines outside [code] such as I write it , I mean replace new line with <BR>.
and every lines inside [code] make it inside textarea.
so you want whatever is typed in between the [code] tags to b eplaced into a text box? so the code between those tags is inside this textbox that I am using to type this message?
Say a user types in this:
He wants to convert it to this:Quote:
blah blah lines blah blah
blah blah blah lines
blah blah fublah
[quode]
my wonderful code
goes here
[/quode]
Am I correct prokhaled?Quote:
blah blah lines blah blah<br>
blah blah blah lines<br>
blah blah fublah<br>
<textarea>
my wonderful code
goes here
</textarea>
Yes M.R Hobo you are correct.
how do i delete stuff like :
[ b ]
[ b:7777790783903094878314 ]
(note the numbers can be anything)
I wanna strip BB Code from a module to show the recent posts on my homepage
: i used string replacement to alter :) to a smile image etc.. but i wanna be able to use random numbers, like a match all