|
-
Aug 10th, 2002, 04:45 PM
#1
Thread Starter
Hyperactive Member
one preg_replace
I need one perg_replace function to replace "\r\n" with "<br>" except "\r\n" that beetween [textarea] and [/textarea]
is this impossible ?
-
Aug 10th, 2002, 05:35 PM
#2
Lively Member
for you????? no, it is not possible
Just Imagine what you can do with the power of php.
257 Tutorials and counting.
529 Snippets and growing.
Add yours today @
SnippetLibrary.com
-
Aug 10th, 2002, 06:04 PM
#3
Thread Starter
Hyperactive Member
Originally posted by scoutt
for you????? no, it is not possible
M.R scoutt
What about for others ?
-
Aug 10th, 2002, 08:12 PM
#4
Lively Member
for others, they understand php
your funny........
Just Imagine what you can do with the power of php.
257 Tutorials and counting.
529 Snippets and growing.
Add yours today @
SnippetLibrary.com
-
Aug 11th, 2002, 01:39 AM
#5
Thread Starter
Hyperactive Member
All
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 ..
-
Aug 11th, 2002, 06:11 AM
#6
Fanatic Member
so why not post what you have and then allow us to help you from that?
-
Aug 11th, 2002, 07:46 AM
#7
Thread Starter
Hyperactive Member
All I have
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)
-
Aug 11th, 2002, 10:38 AM
#8
Thread Starter
Hyperactive Member
-
Aug 11th, 2002, 11:54 AM
#9
Stuck in the 80s
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.
-
Aug 11th, 2002, 11:59 AM
#10
Fanatic Member
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.
-
Aug 11th, 2002, 12:45 PM
#11
Thread Starter
Hyperactive Member
clearing the problem
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
Last edited by prokhaled; Aug 11th, 2002 at 12:51 PM.
-
Aug 11th, 2002, 12:56 PM
#12
Fanatic Member
I want to echo text that inside this textarea in another page so I replace new line with "<BR>"
dont do that step
-
Aug 11th, 2002, 01:09 PM
#13
Thread Starter
Hyperactive Member
this step
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
_________________________________________
-
Aug 11th, 2002, 01:12 PM
#14
Fanatic Member
so use this as your echo:
echo nl2br($text);
That way you do not have to modify its contents
-
Aug 12th, 2002, 04:51 PM
#15
Thread Starter
Hyperactive Member
echo nl2br($text);
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]
-
Aug 12th, 2002, 04:57 PM
#16
Fanatic Member
NO!!
You use that echo for when you need to print it to the page, you only use:
when outputing in the <textarea>
-
Aug 12th, 2002, 06:10 PM
#17
Thread Starter
Hyperactive Member
Relly
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.
-
Aug 12th, 2002, 06:19 PM
#18
Fanatic Member
a textarea reads \n\r as new lines. HTML does not! Try it and see for yourself
-
Aug 13th, 2002, 02:42 AM
#19
Thread Starter
Hyperactive Member
True
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>
-
Aug 13th, 2002, 09:35 AM
#20
Fanatic Member
DONT REPLACE IT!!
PHP Code:
// To Screen
echo nl2br($text);
// To textarea
echo "<textarea>$text</textarea>";
-
Aug 13th, 2002, 12:33 PM
#21
Thread Starter
Hyperactive Member
No
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]
-
Aug 13th, 2002, 12:34 PM
#22
Stuck in the 80s
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?
-
Aug 13th, 2002, 12:35 PM
#23
Stuck in the 80s
Re: No
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]
hmmm...is this all user typed?
-
Aug 13th, 2002, 01:40 PM
#24
Lively Member
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.
Last edited by scoutt; Aug 13th, 2002 at 01:48 PM.
Just Imagine what you can do with the power of php.
257 Tutorials and counting.
529 Snippets and growing.
Add yours today @
SnippetLibrary.com
-
Aug 13th, 2002, 02:01 PM
#25
Stuck in the 80s
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.
-
Aug 13th, 2002, 02:03 PM
#26
Stuck in the 80s
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;
}
?>
-
Aug 13th, 2002, 02:48 PM
#27
Thread Starter
Hyperactive Member
yes, please come again. I need your help
M.R scoutt And M.R Hebo , that is the code that I use.
Code:
$SubjectText=$Row[SubjectText]
$SubjectText = str_replace("
Code:
", "<textarea type=text name=ms rows=8 cols=70 wrap='virtual'>", $SubjectText);
$SubjectText = str_replace("
", "</textarea>", $SubjectText);
$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.
-
Aug 13th, 2002, 03:01 PM
#28
Lively Member
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);
$SubjectText = str_replace("\r\n", " <BR> ",$SubjectText);
if that is all you are doing then take the
$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);
Just Imagine what you can do with the power of php.
257 Tutorials and counting.
529 Snippets and growing.
Add yours today @
SnippetLibrary.com
-
Aug 13th, 2002, 03:24 PM
#29
Thread Starter
Hyperactive Member
the same problem
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";
___________________
-
Aug 13th, 2002, 04:28 PM
#30
Lively Member
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????
Just Imagine what you can do with the power of php.
257 Tutorials and counting.
529 Snippets and growing.
Add yours today @
SnippetLibrary.com
-
Aug 13th, 2002, 05:07 PM
#31
Thread Starter
Hyperactive Member
I do not understand
I do not understand .. that is for example.
-
Aug 13th, 2002, 07:49 PM
#32
Stuck in the 80s
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????
from a database, I believe?
-
Aug 13th, 2002, 08:41 PM
#33
Lively Member
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.
Just Imagine what you can do with the power of php.
257 Tutorials and counting.
529 Snippets and growing.
Add yours today @
SnippetLibrary.com
-
Aug 13th, 2002, 09:06 PM
#34
Stuck in the 80s
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.
chill out
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.
-
Aug 13th, 2002, 09:20 PM
#35
Lively Member
Just Imagine what you can do with the power of php.
257 Tutorials and counting.
529 Snippets and growing.
Add yours today @
SnippetLibrary.com
-
Aug 14th, 2002, 03:00 AM
#36
Thread Starter
Hyperactive Member
yes
_________________________
that is a new php code
open NotePad and write it
[textarea]
<?
echo "A";
echo "B";
?>
[/textarea]
_________________________
yes, this text come from database.
-
Aug 14th, 2002, 07:27 AM
#37
Lively Member
how is it going into the DB
Just Imagine what you can do with the power of php.
257 Tutorials and counting.
529 Snippets and growing.
Add yours today @
SnippetLibrary.com
-
Aug 14th, 2002, 09:47 AM
#38
Thread Starter
Hyperactive Member
any user
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.
-
Aug 14th, 2002, 10:06 AM
#39
Stuck in the 80s
Re: yes, please come again. I need your help
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.
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.
Originally posted by scoutt
up yours Hobo
I don't swing that way, man.
-
Aug 14th, 2002, 11:31 AM
#40
Lively Member
Re: any user
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.
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.
Just Imagine what you can do with the power of php.
257 Tutorials and counting.
529 Snippets and growing.
Add yours today @
SnippetLibrary.com
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|