Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replacing Line Breaks On Condition

Status
Not open for further replies.

megamanXplosion

Technical User
Sep 5, 2002
1
US
I have a message board (invision board) and I've successfully modified it so that I can use [script] and [/script] tags to use JavaScript within the posts (Yes I'm aware of security issues, how many times have I been asked that? lol) Anyways, the message board's post_parser.php file automatically converts line breaks into < br> tags, and here is the code that is used to do so....

$txt = preg_replace( &quot;/\n/&quot;, &quot;<br>&quot;, $txt );

and then there's another similar line which unconverts the linebreaks. I was wondering if someone could tell me how to rewrite that so it'll still replace all of the line breaks, but not those in between [script] and [/script] tags.


If you need an example of what I mean then, here is a simple JavaScript that I would write into a post.

[script]
document.write(&quot;Hello&quot;);
[/script]

the message board would parse this and output it like this...

<script><br>
document.write(&quot;Hello&quot;);<br>
</script>

and that would cause errors. Any help would be greatly appreciated :)
 
what about first copying the data between the [script][/script] tags and then replacing it after the line break conversion? Bastien

There are many ways to skin this cat,
but it still tastes like chicken
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top