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
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: -
$_start = array(5 => true, 12 => true);
-
$_end = array(10 => true, 18 => true);
-
-
$html = '';
-
for( $_i = 0; isset($str[$_i]); ++$i )
-
{
-
if( ! empty($_start[$_i]) )
-
{
-
$html .= '<span style="background-color: $ffcc00;">';
-
}
-
-
$html .= $str[$_i];
-
-
if( ! empty($_end[$_i]) )
-
{
-
$html .= '</span>';
-
}
-
}
-
-
echo $html;
-
This code assumes that there is an end index for every start index and that no ranges overlap each other.
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). -
<?php
-
$_start = array(5 => true, 12 => true);
-
-
$_end = array(10 => true, 18 => true);
-
-
$str='ABCDREGYRIWJEKSALOPRHDAGRTPRTDBRTWASERFSDHSJHDS';
-
-
-
$html = '';
-
-
for( $_i = 0; isset($str[$_i]); ++$i )
-
-
{
-
-
if( ! empty($_start[$_i]) )
-
-
{
-
-
$html .= '<span style="background-color: $ffcc00;">';
-
-
}
-
-
-
-
$html .= $str[$_i];
-
-
-
-
if( ! empty($_end[$_i]) )
-
-
{
-
-
$html .= '</span>';
-
-
}
-
-
}
-
-
-
-
echo $html;
-
?>
-
thanks
kumar
pbmods 5,821
Recognized Expert Expert
Heya, Kumar.
Please use CODE tags when posting source code:
[CODE=php]
PHP code goes here.
[/CODE]
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'.
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
pbmods 5,821
Recognized Expert Expert
Heya, Kumar.
Yes. It looks like I made another typo. -
$html .= '<span style="background-color: $ffcc00;">';
-
Should be: -
$html .= '<span style="background-color: #ffcc00;">';
-
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
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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Rizyak |
last post by:
********************
alt.php.sql,comp
databases.ms-sqlserver
microsoft.public.sqlserver.programming
***********************************
Why doesn't this work:
SELECT *
FROM 'Events'
|
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...
|
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...
|
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?
|
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($)
| |
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...
|
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>
|
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.
|
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...
|
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...
|
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. ...
| |
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...
|
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...
|
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...
|
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...
|
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...
|
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
| |
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...
| |