473,563 Members | 2,916 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

multiple string matching

55 New Member
Hi All,
I have a string of around 500 characters(alph abets) and I have a 3 arrays storing the position "start, end and type" for that string. i am trying to do is to match these position to the string and highlight those positions on the web page.

For example: string- ABCDREGYRIWJEKS ALOPRHDAGRTPRTD BRTWASERFSDHSJH DS

start_pos=5
end_pos=10
type=helix breaker

start_pos=12
end_pos=18
type=unusual

so what I am trying to do is to match the pos and type to the string and
in the output(webpage) , trying to highlight the positions, may be drawing a rectangular box around the matched positions.and positions may overlap within each other.

I am tying to use some of the functions for the string matching but unable to do for multiple matches.



any help or suggestions.

Thanks
Kumar
Sep 16 '07 #1
8 2824
pbmods
5,821 Recognized Expert Expert
Heya, Kumar.

The only way to do this reliably would be to output HTML to set the background color of the characters.

My recommendation would be to compile all your start indexes into an array and your end indexes into a separate array. Then loop through your string and output it progressively:
Expand|Select|Wrap|Line Numbers
  1. $_start = array(5 => true, 12 => true);
  2. $_end = array(10 => true, 18 => true);
  3.  
  4. $html = '';
  5. for( $_i = 0; isset($str[$_i]); ++$i )
  6. {
  7.     if( ! empty($_start[$_i]) )
  8.     {
  9.         $html .= '<span style="background-color: $ffcc00;">';
  10.     }
  11.  
  12.     $html .= $str[$_i];
  13.  
  14.     if( ! empty($_end[$_i]) )
  15.     {
  16.         $html .= '</span>';
  17.     }
  18. }
  19.  
  20. echo $html;
  21.  
This code assumes that there is an end index for every start index and that no ranges overlap each other.
Sep 16 '07 #2
kumarboston
55 New Member
Hi,
Thanks for the response, I tried tho run the code with a test string, it showed me error of memory size limit. I am posting the code(php).
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.       $_start = array(5 => true, 12 => true);
  3.  
  4.       $_end = array(10 => true, 18 => true);
  5.  
  6.  $str='ABCDREGYRIWJEKSALOPRHDAGRTPRTDBRTWASERFSDHSJHDS';
  7.  
  8.  
  9.       $html = '';
  10.  
  11.       for( $_i = 0; isset($str[$_i]); ++$i )
  12.  
  13.       {
  14.  
  15.           if( ! empty($_start[$_i]) )
  16.  
  17.          {
  18.  
  19.               $html .= '<span style="background-color: $ffcc00;">';
  20.  
  21.           }
  22.  
  23.  
  24.  
  25.           $html .= $str[$_i];
  26.  
  27.  
  28.  
  29.           if( ! empty($_end[$_i]) )
  30.  
  31.           {
  32.  
  33.               $html .= '</span>';
  34.  
  35.           }
  36.  
  37.       }
  38.  
  39.  
  40.  
  41.       echo $html;
  42. ?>
  43.  
thanks
kumar
Sep 16 '07 #3
pbmods
5,821 Recognized Expert Expert
Heya, Kumar.

Please use CODE tags when posting source code:

[CODE=php]
PHP code goes here.
[/CODE]
Sep 16 '07 #4
pbmods
5,821 Recognized Expert Expert
Heya, Kumar.

A 'memory limit exceeded' error generally means an infinite loop, and sure enough, I put '++$i' in my for loop instead of '++$_i'.
Sep 16 '07 #5
kumarboston
55 New Member
Thanks for the help and resposnse.
I ran the code again with [++$_i], its simply printing the $str string.

Am i missing something??

thanks once again for your time and patience.

kumar
Sep 16 '07 #6
pbmods
5,821 Recognized Expert Expert
Heya, Kumar.

Yes. It looks like I made another typo.
Expand|Select|Wrap|Line Numbers
  1. $html .= '<span style="background-color: $ffcc00;">';
  2.  
Should be:
Expand|Select|Wrap|Line Numbers
  1. $html .= '<span style="background-color: #ffcc00;">';
  2.  
Sep 16 '07 #7
kumarboston
55 New Member
Thanks so much
the code is working and its highlighting the start and the end points.
I was wondering if i want to print the position exactly below the start match and the end match , then should i have to specify the column.
because right now i am printing the position which is not below the matched charecters.

kumar
Sep 16 '07 #8
pbmods
5,821 Recognized Expert Expert
Heya, Kumar.

You'll want to enclose your characters inside of <pre> tags. You can create an additional variable to hold the positional data; simply output a space character if the current position is not special, or else $_i if it is.

It gets a bit tricky when you get into double digits, but not impossible.
Sep 16 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

6
7196
by: Rizyak | last post by:
******************** alt.php.sql,comp databases.ms-sqlserver microsoft.public.sqlserver.programming *********************************** Why doesn't this work: SELECT * FROM 'Events'
1
4548
by: Oat | last post by:
I am a little stomped and wandering if someone might have an idea how to go about doing this. following on from this guide http://www.4guysfromrolla.com/webtech/031004-1.shtml on matching a comma-delimited string, I would like to expand on this and match two comma-delimited string in a sproc. In my database, table A have a city field...
1
20759
by: KLAU | last post by:
I have a field that retrieves information from an expression in a query. I have used a DLookup function to get the calculated field from the query. However, the relationship is 1-to-many so one site could have many units. How do I have the DLookUp field value change to a newly calcuated field when I navigate through the units? please see...
5
22931
by: Christine | last post by:
I have a text file that appears to be delimited by multiple spaces. The split function will only work with one space if I am correct. Is there some way to split this file into an array without getting the extra spaces?
5
5738
by: olaufr | last post by:
Hi, I'd need to perform simple pattern matching within a string using a list of possible patterns. For example, I want to know if the substring starting at position n matches any of the string I have a list, as below: sentence = "the color is $red" patterns = pos = sentence.find($)
52
6276
by: MP | last post by:
Hi trying to begin to learn database using vb6, ado/adox, mdb format, sql (not using access...just mdb format via ado) i need to group the values of multiple fields - get their possible variations(combination of fields), - then act on each group in some way ...eg ProcessRs (oRs as RecordSet)... the following query will get me the...
5
8767
by: mikko.n | last post by:
I have recently been experimenting with GNU C library regular expression functions and noticed a problem with pattern matching. It seems to recognize only the first match but ignoring the rest of them. An example: mikko.c: ----- #include <stdio.h> #include <regex.h>
5
3298
by: Max | last post by:
Is there any way to set a select-multiple type <select multiple="multiple"with multiple selected options in scripting? Any idea about this is appreciative.
11
4814
by: tech | last post by:
Hi, I need a function to specify a match pattern including using wildcard characters as below to find chars in a std::string. The match pattern can contain the wildcard characters "*" and "?", where "*" matches zero or more consecutive occurrences of any character and "?" matches a single occurrence of any character. Does boost or some...
0
7583
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7885
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8106
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7638
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7948
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5484
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2082
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
923
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.