PDA

Click to See Complete Forum and Search --> : one preg_replace


prokhaled
Aug 10th, 2002, 04:45 PM
I need one perg_replace function to replace "\r\n" with "<br>" except "\r\n" that beetween and

is this impossible ?

scoutt
Aug 10th, 2002, 05:35 PM
for you????? no, it is not possible

prokhaled
Aug 10th, 2002, 06:04 PM
Originally posted by scoutt
for you????? no, it is not possible

M.R scoutt
What about for others ?

scoutt
Aug 10th, 2002, 08:12 PM
for others, they understand php
your funny........ :D

prokhaled
Aug 11th, 2002, 01:39 AM
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 ..

cpradio
Aug 11th, 2002, 06:11 AM
so why not post what you have and then allow us to help you from that?

prokhaled
Aug 11th, 2002, 07:46 AM
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)

prokhaled
Aug 11th, 2002, 10:38 AM
is that may help me ?

http://www.php.net/manual/en/function.nl2br.php

The Hobo
Aug 11th, 2002, 11:54 AM
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:

cpradio
Aug 11th, 2002, 11:59 AM
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.

prokhaled
Aug 11th, 2002, 12:45 PM
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

<?
echo "A";
echo "B";
?>

---------------------------------------

I want to echo text that inside this textarea in another page so I replace new line with "<BR>" so and also replace with <textarea> and 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

cpradio
Aug 11th, 2002, 12:56 PM
I want to echo text that inside this textarea in another page so I replace new line with "<BR>"
dont do that step

prokhaled
Aug 11th, 2002, 01:09 PM
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
_________________________________________

cpradio
Aug 11th, 2002, 01:12 PM
so use this as your echo:

echo nl2br($text);

That way you do not have to modify its contents

prokhaled
Aug 12th, 2002, 04:51 PM
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 and

cpradio
Aug 12th, 2002, 04:57 PM
NO!!

You use that echo for when you need to print it to the page, you only use:

echo $text; when outputing in the <textarea>

prokhaled
Aug 12th, 2002, 06:10 PM
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.

cpradio
Aug 12th, 2002, 06:19 PM
a textarea reads \n\r as new lines. HTML does not! Try it and see for yourself

prokhaled
Aug 13th, 2002, 02:42 AM
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>

cpradio
Aug 13th, 2002, 09:35 AM
DONT REPLACE IT!!

// To Screen
echo nl2br($text);

// To textarea
echo "<textarea>$text</textarea>";

prokhaled
Aug 13th, 2002, 12:33 PM
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

<?
echo "A";
echo "B";
?>

____________________

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 and

The Hobo
Aug 13th, 2002, 12:34 PM
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?

The Hobo
Aug 13th, 2002, 12:35 PM
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

<?
echo "A";
echo "B";
?>

____________________

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 and

hmmm...is this all user typed?

scoutt
Aug 13th, 2002, 01:40 PM
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.

The Hobo
Aug 13th, 2002, 02:01 PM
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.

The Hobo
Aug 13th, 2002, 02:03 PM
Try working with this code that I posted in one of your previous threads. You should be able to modify it to work:

<?php
$test1 = "Hi how Are you A A A Fine A A A any text A ";
echo "Test1 = " . $test1 . "<br>After Function, = " . convert($test1) . "<br><br>";

//THE FUNCTION:
function convert($text) {
if (!strpos($text, "") === false) {
do {
$pos = strpos($text, "[E]", $epos);
$ntext .= str_replace("A", "B", substr($text, $epos, $pos - $epos)); // . "<br>";

$epos = strpos($text, "", $pos) + 4;
$ntext .= substr($text, $pos, $epos - $pos);
} while (!strpos($text, "[E]", $epos) === false);

} else {
$ntext = str_replace("A", "B", $text);
}

return $ntext;
}
?>

prokhaled
Aug 13th, 2002, 02:48 PM
M.R scoutt And M.R Hebo , that is the code that I use.


$SubjectText=$Row[SubjectText]
$SubjectText = str_replace("", "<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.

scoutt
Aug 13th, 2002, 03:01 PM
$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.....

$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);

prokhaled
Aug 13th, 2002, 03:24 PM
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

<?
echo "A";
echo "B";
?>

---------------------------------------

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";
___________________

scoutt
Aug 13th, 2002, 04:28 PM
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

<?
echo "A";
echo "B";
?>



coming from????

prokhaled
Aug 13th, 2002, 05:07 PM
I do not understand .. that is for example.

The Hobo
Aug 13th, 2002, 07:49 PM
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

<?
echo "A";
echo "B";
?>



coming from????

from a database, I believe?

scoutt
Aug 13th, 2002, 08:41 PM
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.

The Hobo
Aug 13th, 2002, 09:06 PM
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 :rolleyes:

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.

scoutt
Aug 13th, 2002, 09:20 PM
up yours Hobo

prokhaled
Aug 14th, 2002, 03:00 AM
_________________________
that is a new php code
open NotePad and write it

<?
echo "A";
echo "B";
?>

_________________________

yes, this text come from database.

scoutt
Aug 14th, 2002, 07:27 AM
how is it going into the DB

prokhaled
Aug 14th, 2002, 09:47 AM
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.

The Hobo
Aug 14th, 2002, 10:06 AM
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.

scoutt
Aug 14th, 2002, 11:31 AM
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.

prokhaled
Aug 14th, 2002, 02:23 PM
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] ?

scoutt
Aug 14th, 2002, 04:23 PM
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.

prokhaled
Aug 14th, 2002, 04:57 PM
all text go to one cell (1 DB column)

scoutt
Aug 14th, 2002, 05:30 PM
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.

prokhaled
Aug 15th, 2002, 01:34 AM
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

scoutt
Aug 15th, 2002, 07:28 AM
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.

prokhaled
Aug 15th, 2002, 07:44 AM
I have reply text . I use this code to insert reply to DB



$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','$At tach','0','$ActiveUrl','$ShowSignature')";
$Result = mysql_query($Sql);

scoutt
Aug 15th, 2002, 07:56 AM
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

prokhaled
Aug 15th, 2002, 09:45 AM
user can Insert ReplyText like that

Good Code
Write It now

Any
Code
Here



I want when I show this reply disply:
_________
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.

scoutt
Aug 15th, 2002, 10:01 AM
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?

prokhaled
Aug 15th, 2002, 12:05 PM
GOOD.
Yes that is what I mean. you are right.

scoutt
Aug 15th, 2002, 02:31 PM
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?

prokhaled
Aug 15th, 2002, 03:07 PM
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.

scoutt
Aug 15th, 2002, 03:30 PM
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?

The Hobo
Aug 15th, 2002, 04:13 PM
Say a user types in this:

blah blah lines blah blah
blah blah blah lines
blah blah fublah

my wonderful code
goes here


He wants to convert it to this:

blah blah lines blah blah<br>
blah blah blah lines<br>
blah blah fublah<br>
<textarea>
my wonderful code
goes here
</textarea>

Am I correct prokhaled?

prokhaled
Aug 15th, 2002, 04:38 PM
Yes M.R Hobo you are correct.

wpearsall
Aug 18th, 2002, 06:35 PM
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