Jump to content


Photo

Urgent Help needed!


  • Please log in to reply
20 replies to this topic

#1 Gruzin

Gruzin
  • Members
  • PipPipPip
  • Advanced Member
  • 448 posts
  • LocationGeorgia

Posted 26 July 2006 - 02:06 PM

Hope u guys can help me, I've got a problem:
I've got a form where I input some text, but I cann't make a space between lines (kind of paragraph); please help me, I really need this  :'(

Here is the code:

<?php
$link = "admin.php";
$linkShow = "Your info is saved";
$text = stripslashes($_POST["text"]);
$text_file = "text/homepage.txt";
$name_gax = file($text_file); //opens with array
$text_open = fopen($text_file, "w+"); //open message file with write
fputs($text_open, $text);
fclose($text_open);
echo "<a href='".$link."'>".$linkShow;
?>
I don't need your script, I'll try to write it myself

#2 ozPATT

ozPATT
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 26 July 2006 - 02:08 PM

this any good?

$text = stripslashes (preg_replace(array("/\r?\n\r?\n/","/\r\n/"),array("</p>\n\n<p>","<br />\n"),$_POST['text']));


#3 Gruzin

Gruzin
  • Members
  • PipPipPip
  • Advanced Member
  • 448 posts
  • LocationGeorgia

Posted 26 July 2006 - 02:11 PM

thanks man :) can u explain me how does it work?
I don't need your script, I'll try to write it myself

#4 ozPATT

ozPATT
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 26 July 2006 - 02:13 PM

if only i could!

haha, it is a piece of code that I acquired some time ago, and uses regular expressions. Basically, it replaces any line returns from the textarea, with the paragraph and break tags that html uses.

eg

\r\n is one line break or return. so that should be <br />. two of them, equal a paragraph, which is <p></p>.

Pretty clever really. Did it do what you wanted?

#5 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 26 July 2006 - 02:15 PM

Why not just use nl2br()? Alot simpler. Does the samething.

nl2br converts any newline characters (\r\n, \r, \n) to < br /> (without the space before the br).

#6 Gruzin

Gruzin
  • Members
  • PipPipPip
  • Advanced Member
  • 448 posts
  • LocationGeorgia

Posted 26 July 2006 - 02:15 PM

ye I've done it! you"ve saved me ozPATT, cheers mate:)
I don't need your script, I'll try to write it myself

#7 ozPATT

ozPATT
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 26 July 2006 - 02:16 PM

is that a predefined function? never heard of it.

glad to help Gruzin

#8 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 26 July 2006 - 02:20 PM

nl2br has been around since PHP3. Check it out here

#9 Gruzin

Gruzin
  • Members
  • PipPipPip
  • Advanced Member
  • 448 posts
  • LocationGeorgia

Posted 26 July 2006 - 02:21 PM

wildteen88  do u mean something like this?

$text = stripslashes (nl2br($_POST['text']));

it doesn't work......
I don't need your script, I'll try to write it myself

#10 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 26 July 2006 - 02:25 PM

it doesn't work

covers a lot of ground. What doesn't work? What did you expect?

I would do the functions is this order:
<?php $text = nl2br(stripslashes($_POST['text'])); ?>

Ken

#11 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 26 July 2006 - 02:25 PM

remove stripslashes.

#12 Gruzin

Gruzin
  • Members
  • PipPipPip
  • Advanced Member
  • 448 posts
  • LocationGeorgia

Posted 26 July 2006 - 02:36 PM

it works, why remove srtipslashes?

Thanks guys:)
I don't need your script, I'll try to write it myself

#13 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 26 July 2006 - 02:48 PM

Beacuase it intefere with nl2br and the whitepace characters (\n, \r, etc).

#14 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 26 July 2006 - 02:55 PM

That's why I suggested to reverse the order of the functions.

Ken

#15 Gruzin

Gruzin
  • Members
  • PipPipPip
  • Advanced Member
  • 448 posts
  • LocationGeorgia

Posted 26 July 2006 - 02:57 PM

ok, another question if I won't distrub you:

when I input the text and need to write bold text or link it, how can I do that?
Thanks
I don't need your script, I'll try to write it myself

#16 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 26 July 2006 - 03:02 PM

You need to output the correct HTML tags along with the text.

For bolding:
(the old way)
<?php echo '<b>' . $text . '</b>'; ?>
(the new way)
<?php echo '<span style="font-weight:bold">' . $text . '</span>'; ?>

To create a link:
<?php echo '<a href="http://url.goes.here/">' . $text . '</a>'; ?>

Ken

#17 Gruzin

Gruzin
  • Members
  • PipPipPip
  • Advanced Member
  • 448 posts
  • LocationGeorgia

Posted 26 July 2006 - 03:04 PM

thanks a lot, everyday I find out something new on this great forum:)
I don't need your script, I'll try to write it myself

#18 Gruzin

Gruzin
  • Members
  • PipPipPip
  • Advanced Member
  • 448 posts
  • LocationGeorgia

Posted 26 July 2006 - 03:17 PM

how can I make a form like in this forum, when u click a button text becomes bold or u make it linked?
I don't need your script, I'll try to write it myself

#19 Gruzin

Gruzin
  • Members
  • PipPipPip
  • Advanced Member
  • 448 posts
  • LocationGeorgia

Posted 26 July 2006 - 03:28 PM

somebody please help:(
I don't need your script, I'll try to write it myself

#20 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 26 July 2006 - 03:30 PM

This is called BBCode. Search google for BBCode Inserter or something like that. It requires javascript. But to replace the BBCodes ie [ b]hello[/b] in to hello will require the use of regular expressions. Here is a very basic BBCode Parser, it parses bold, italic and underline BBCode.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users