473,394 Members | 1,785 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,394 software developers and data experts.

Search Results substring

Nel
Hi all,

I have been searching for some clues as to how to show a substring from a
database search.

$pagetitle = "Page Title";
$pagetext = "This is <b>a typical</b> string that would be stored<br>in the
database.";
Search for "that"

results would look like

1. Page Title
...string that would...
2. Another page
...computers that can...
3. Further Page
...languages that are...

At the moment the search results just show the page title. The idea is that
in the set of results I can show the user the context of each result, a bit
like a search engine does. Ideall I would like up to 10 words either side
of the search keyword.

BTW php+ mysql

Nel.

Jul 17 '05 #1
3 2261
Nel wrote:
Hi all,

I have been searching for some clues as to how to show a substring from a
database search.

$pagetitle = "Page Title";
$pagetext = "This is <b>a typical</b> string that would be stored<br>in
the database.";
Search for "that"

results would look like

1. Page Title
...string that would...
2. Another page
...computers that can...
3. Further Page
...languages that are...

At the moment the search results just show the page title. The idea is
that in the set of results I can show the user the context of each result,
a bit
like a search engine does. Ideall I would like up to 10 words either side
of the search keyword.

BTW php+ mysql

Nel.

Hi Nel,

use LIKE

SELECT pagetext FROM tblpagetext WHERE (pagetext LIKE '%that%');

Because we don't know how your database is designed it is impossible to say
how the pagetitle should be retrieved.
I expect you reference a foreign key in tblpagetext on the PK in
tblpagetitle??

Anyway, if you have the pagetext in it is easy to get some words around it.
use explode on space and find the location of the first 'that' and get 5
before and 5 after (if possible).
go to www.php.net and browse a little for explode and count and the like.
I am quite sure somebody handy with regexpressions codes this in 1 line. :-)

Good luck!

Regards,
Erwin Moller
Jul 17 '05 #2
Nel
"Erwin Moller"
<si******************************************@spam yourself.com> wrote in
message news:41***********************@news.xs4all.nl...
Nel wrote:
Hi all,

I have been searching for some clues as to how to show a substring from a database search.

$pagetitle = "Page Title";
$pagetext = "This is <b>a typical</b> string that would be stored<br>in
the database.";
Search for "that"

results would look like

1. Page Title
...string that would...
2. Another page
...computers that can...
3. Further Page
...languages that are...

At the moment the search results just show the page title. The idea is
that in the set of results I can show the user the context of each result, a bit
like a search engine does. Ideall I would like up to 10 words either side of the search keyword.

BTW php+ mysql

Nel.

Hi Nel,

use LIKE

SELECT pagetext FROM tblpagetext WHERE (pagetext LIKE '%that%');

Because we don't know how your database is designed it is impossible to

say how the pagetitle should be retrieved.
I expect you reference a foreign key in tblpagetext on the PK in
tblpagetitle??

Anyway, if you have the pagetext in it is easy to get some words around it. use explode on space and find the location of the first 'that' and get 5
before and 5 after (if possible).
go to www.php.net and browse a little for explode and count and the like.
I am quite sure somebody handy with regexpressions codes this in 1 line. :-)
Good luck!

Regards,
Erwin Moller

Thanks Erwin. I have no problem with the SQL side, just not expereinced in
arrays too much.

If I explode(" ",$pagetext) this will only give me full words. the search
string could be part of a word.

Is there a regex that could just take (up to 40 chars)(searchterm)(up to 40
chars)?

Thanks.

Nel.
Jul 17 '05 #3
Nel
"Nel" <ne***@ne14.co.NOSPAMuk> wrote in message
news:41***********************@ptn-nntp-reader01.plus.net...
"Erwin Moller"
<si******************************************@spam yourself.com> wrote in
message news:41***********************@news.xs4all.nl...
Nel wrote:
Hi all,

I have been searching for some clues as to how to show a substring from
a
database search.

$pagetitle = "Page Title";
$pagetext = "This is <b>a typical</b> string that would be
stored<br>in the database.";
Search for "that"

results would look like

1. Page Title
...string that would...
2. Another page
...computers that can...
3. Further Page
...languages that are...

At the moment the search results just show the page title. The idea is that in the set of results I can show the user the context of each result, a bit
like a search engine does. Ideall I would like up to 10 words either side of the search keyword.

BTW php+ mysql

Nel.

Hi Nel,

use LIKE

SELECT pagetext FROM tblpagetext WHERE (pagetext LIKE '%that%');

Because we don't know how your database is designed it is impossible to

say
how the pagetitle should be retrieved.
I expect you reference a foreign key in tblpagetext on the PK in
tblpagetitle??

Anyway, if you have the pagetext in it is easy to get some words around

it.
use explode on space and find the location of the first 'that' and get 5
before and 5 after (if possible).
go to www.php.net and browse a little for explode and count and the

like. I am quite sure somebody handy with regexpressions codes this in 1 line.

:-)

Good luck!

Regards,
Erwin Moller

Thanks Erwin. I have no problem with the SQL side, just not expereinced

in arrays too much.

If I explode(" ",$pagetext) this will only give me full words. the search
string could be part of a word.

Is there a regex that could just take (up to 40 chars)(searchterm)(up to 40 chars)?

Thanks.

Nel.

I have been messing with
..{0,30}[:alnum: ]($search)[:alnum: ].{0,40}

but this only gives words surrounded by spaces, not part of word or word
followed by , or .

HELP!!!!!!!

Nel.
Jul 17 '05 #4

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

Similar topics

5
by: cassandra.flowers | last post by:
Hi, I have another string handling question for the group, since you have all been so helpful in the past. Thank you. Basically, I want to do something really simple: Search a main...
10
by: Anand Pillai | last post by:
To search a word in a group of words, say a paragraph or a web page, would a string search or a regexp search be faster? The string search would of course be, if str.find(substr) != -1:...
0
by: todd | last post by:
here is a search tool SP I wrote. How many times have you wanted to search all your Stored procs or views (in a database) for a keyword but couldn't!? Well now you can! THis can makes life a...
4
by: gwtc | last post by:
Here is a google search site bookmarklet. This lets you search a certain website using google. What I want is the same thing, but to search a certain geocities site. When you use the current...
3
by: balakrishnan.dinesh | last post by:
Hi frnds, Im having a problem in searching out a particular substring in a string. Here the code: --------------------- <html> <script> var tmpString=" ";
1
by: coolami4u | last post by:
I need a program that simulates the search-and-replace operation in a text editor. The program is to have only three function calls in main. The first function prompts the user to type a string of...
3
by: Richard S | last post by:
CODE: ASP.NET with C# DATABASE: ACCES alright, im having a problem, probably a small thing, but i cant figure out, nor find it in any other post, or on the internet realy (probably cuz i wouldnt...
0
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
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
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...
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.