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.