Jump to content

Auto-Close Tags?


LemonInflux

Recommended Posts

No, not PHP or HTML or whatever. BBCode. What I want to know, is whether PHP can go through a written piece of text, count the number of times something is entered (say, ), and the number of times something else is entered (). Then, if there are more of the first than the second, keep adding the second one on the end until they're equal.

 

Alternatively, is there a way to allow bbc to be used, but if a tag isn't closed, it won't affect the rest of the page?

Link to comment
https://forums.phpfreaks.com/topic/72179-auto-close-tags/
Share on other sites

You would simply search for pairs using your regex so only if they have a proper opening and closing tag they will be replaced with real html:

 

[tag]Some text[/tag] will be replaced with <tag>Some text</tag>

[tag]Some text will not be replaced with <tag>Some text since it is missing a closing tag

 

Then it's up to you if the users improper syntax should be shown or removed.

 

When doing bbcode stuff it's a bad idea to simple search for [tag] and replace with <tab> and afterwards search for [/tag] and replace with </tag>... always search for pairs of opening and closing tags :)

 

 

Maybe have a look at this tutorial: http://www.phpfreaks.com/tutorials/141/0.php

I know it's done with searching for pairs and the problem with non-closed tags have been taken care of :)

Link to comment
https://forums.phpfreaks.com/topic/72179-auto-close-tags/#findComment-363971
Share on other sites

Archived

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

×
×
  • Create New...

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.