Jump to content

Archived

This topic is now archived and is closed to further replies.

Gruzin

Urgent Help needed!

Recommended Posts

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;
?>

Share this post


Link to post
Share on other sites
this any good?

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

Share this post


Link to post
Share on other sites
thanks man :) can u explain me how does it work?

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
ye I've done it! you"ve saved me ozPATT, cheers mate:)

Share this post


Link to post
Share on other sites
is that a predefined function? never heard of it.

glad to help Gruzin

Share this post


Link to post
Share on other sites
nl2br has been around since PHP3. Check it out [url=http://uk2.php.net/manual/en/function.nl2br.php]here[/url]

Share this post


Link to post
Share on other sites
wildteen88  do u mean something like this?

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

it doesn't work......

Share this post


Link to post
Share on other sites
[quote]it doesn't work[/quote]
covers a lot of ground. What doesn't work? What did you expect?

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

Ken

Share this post


Link to post
Share on other sites
it works, why remove srtipslashes?

Thanks guys:)

Share this post


Link to post
Share on other sites
Beacuase it intefere with nl2br and the whitepace characters (\n, \r, etc).

Share this post


Link to post
Share on other sites
That's why I suggested to reverse the order of the functions.

Ken

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
You need to output the correct HTML tags along with the text.

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

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

Ken

Share this post


Link to post
Share on other sites
thanks a lot, everyday I find out something new on this great forum:)

Share this post


Link to post
Share on other sites
how can I make a form like in this forum, when u click a button text becomes bold or u make it linked?

Share this post


Link to post
Share on other sites
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 [b]hello[/b] will require the use of regular expressions. [url=http://www.phpfreaks.com/forums/index.php/topic,101566.msg402102.html#msg402102]Here[/url] is a very basic BBCode Parser, it parses bold, italic and underline BBCode.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.