473,395 Members | 1,689 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

counting tags and writing missing tags

sometimes people just forget to close formating tag while writing
message in forum (or enywhere else) so I wrote those lines (for <b>, <i>
and <a> tags)

$i_open = substr_count($tekst, "<i>");
$i_close = substr_count($tekst, "</i>");
if($i_open > $i_close) {
$tekst = "$tekst </i>";
}

but... I would like to have proper nesting, ie: if someone write
"<b>some text <i>without closing tags"
and if my script have order like
if($b_open > $b_close)
if($i_open > $i_close)
if($a_open > $a_close)

I will have unproper nesting:
"<b>some text <i>without closing tags </b> </i>"

Is there some method to "see" which tag should came first?

--
Ja NE
http://fotozine.org/?omen=janimir
--
Oct 26 '05 #1
1 1539
"Ja NE" wrote:
sometimes people just forget to close formating tag while writing
message in forum (or enywhere else) so I wrote those lines (for <b>, <i>
and <a> tags)

$i_open = substr_count($tekst, "<i>");
$i_close = substr_count($tekst, "</i>");
if($i_open > $i_close) {
$tekst = "$tekst </i>";
}

but... I would like to have proper nesting, ie: if someone write
"<b>some text <i>without closing tags"
and if my script have order like
if($b_open > $b_close)
if($i_open > $i_close)
if($a_open > $a_close)

I will have unproper nesting:
"<b>some text <i>without closing tags </b> </i>"

Is there some method to "see" which tag should came first?


Don't use flags. They won't be of any use if tags of the same type are
nested (e.g., "<b><b>...</b>").

Instead, use a stack to keep a record of which tags are open.

These functions should help:
<http://php.net/array_push>
<http://php.net/array_pop>

--
phil [dot] ronan @ virgin [dot] net
http://vzone.virgin.net/phil.ronan/
Oct 26 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

24
by: Day Bird Loft | last post by:
Web Authoring | Meta-Tags The first thing to understand in regard to Meta Tags is the three most important tags placed in the head of your html documents. They are the title, description, and...
30
by: Toni Mcintyre | last post by:
i'm having 2 problems with the http://validator.w3.org 1. if i have: <meta http-equiv="Content-Script-Type" content="text/javascript"> then why do i need <script type=text/javascript>...
7
by: zets | last post by:
I need a macro for counting the bits in the odd positions of a given input (of any type, char, pointer, int, struct, whatever). Is there any clever way I could not think of, to do it efficiently? ...
2
by: Sagar | last post by:
Hi Friends, Please forgive me if this question has appeared before. If so please give me a link or some clue on this problem. I'm writing XML comments to build Comment Web Pages by using...
3
by: Flip | last post by:
Does c#/.net support custom tags like j2ee does? I don't mean to start a flaming war, I'm just honestly looking to find out. From what I've seen/google'd it doesn't, so I just thought I would ask...
8
by: Mark | last post by:
We have a multi-line textbox that users copy and paste email text into. The pasted text frequently will contain a tag like <blah@aol.com> or similar. I believe .NET is protecting itself from code...
14
by: jpr | last post by:
Friends, I have a form with four fields, date1, date2, date3 and date4. All these have all a mm/dd/yyyy format and have their source to a table. I need to add an unbound control (I will name...
27
by: Simon Biber | last post by:
I was reading http://en.wikipedia.org/wiki/Poker_probability which has a good description of how to count the frequency of different types of poker hands using a mathematical approach. A sample...
4
by: saritha2008 | last post by:
Hi, Iam working on converting one of xml file to other form of xml using XSLT. As part of this, I need to count the no. of "component" nodes in the xml file given below. If there is only one...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.