vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Help with preg_replace and regexp (https://vborg.vbsupport.ru/showthread.php?t=124357)

makaiguy 08-19-2006 12:13 AM

Help with preg_replace and regexp
 
Working on a small PHP mailer form project on Apache v1.3.36 to sent html-formatted mail.

Form is POSTed with message text in a textarea named COMMENT. Some code I'm adapting uses the following to strip linefeeds and replace with html breaks:
Code:

$comment = preg_replace("/\n/","\n<BR>",$_POST[COMMENT]);
Only problem is that any apostrophes in the submitted message get a \ inserted before them. Thus "it's" becomes "it\'s" in the received mail.

I don't know beans about regular expressions. Can anybody help straighten this out?

Or is there something else that needs to be done to have apostrophes show up correctly?

harmor19 08-19-2006 12:30 AM

Below that line add

PHP Code:

$comment stripslashes($comment); 


Code Monkey 08-19-2006 12:35 AM

Why don't you just use the php function nl2br();

nl2br(string string) //Inserts HTML line breaks before all newlines in a string

makaiguy 08-19-2006 12:48 AM

Quote:

Originally Posted by harmor19
Below that line add

PHP Code:

$comment stripslashes($comment); 


Works wonderfully, thanks! And much to my surprise it even leaves slashes originally entered as part of the text intact.

Quote:

Originally Posted by Code Monkey
Why don't you just use the php function nl2br();

nl2br(string string) //Inserts HTML line breaks before all newlines in a string

Thanks for this. It's certainly easier for me to understand the coding without having to deal with the regex.

But still getting the \' , so still have to use stripslashes().

Any idea which of the two approaches is less server intensive?

Code Monkey 08-19-2006 02:13 AM

well, nl2br was made to do that and only that, so I would guess that is the best method.


All times are GMT. The time now is 06:20 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01849 seconds
  • Memory Usage 1,722KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code_printable
  • (2)bbcode_php_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (5)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete