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 (https://vborg.vbsupport.ru/showthread.php?t=64010)

JulianD 04-17-2004 07:17 PM

Help with preg_replace
 
Hi.

I'm a completely noob when it comes to regexp, so I guess I can post here for a little help :p

I need to replace all the <br /> on a variable to simple line breaks (\n). The problem is that I need to replace the <br />'s that are ONLY inside a special tag, for example, the <myhtml> and </myhtml> tags.

See:

Code:

<html>
<head><title></title>
</head>
<body>
.
.
.
<myhtml>
Here is some text<br />
and some more text<br />
Bye.
</myhtml>
.
.
.
</body></html>

So, what I want is to convert all the <br />'s inside the <myhtml> tags to simple line breaks.

Is that possible? Please help!!

filburt1 04-17-2004 07:43 PM

PHP Code:

$foo preg_replace("/<myhtml>(.*)<\/myhtml>/siU""\\1"$foo);
$foo str_replace("<br />""\n"$foo); 


Boofo 04-17-2004 07:46 PM

How would you do that with vbcode tags like the php tags?

JulianD 04-17-2004 10:32 PM

Hi filburt1. Thanks for your code, but it doesn't work as it should :(

It replaces absolutely all the <br />'s on the variable... But I only need to replace the <br />'s that are inside the <myhtml> and </myhtml> tags.

For example:

This:

Code:

<html>
<head><title></title>
</head>
<body>
.
.
Text out side<br />
of the myhtml tags<br />
.
<myhtml>
Here is some text<br />
and some more text<br />
Bye.
</myhtml>
.
.
.
</body></html>

would turn into this:

Code:

<html>
<head><title></title>
</head>
<body>
.
.
Text out side<br />
of the myhtml tags<br />
.
<myhtml>
Here is some text\n
and some more text\n
Bye.
</myhtml>
.
.
.
</body></html>


If you could help me with that one, I will thank you my whole life ;)! :p


All times are GMT. The time now is 01:29 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.01036 seconds
  • Memory Usage 1,716KB
  • 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
  • (3)bbcode_code_printable
  • (1)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (4)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