473,836 Members | 2,051 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2283
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************ *************** *************** @spamyourself.c om> 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)(searchte rm)(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.n et...
"Erwin Moller"
<si************ *************** *************** @spamyourself.c om> 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)(searchte rm)(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
6738
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 string for a substring, then count how many times the
10
39365
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: domything() And the regexp search assuming no case restriction would be,
0
3671
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 lot easier for developers. Would you email me and let me know which part of the world my code is running in?
4
3576
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 bookmarklet, the search takes you to site:www.geocities.com instead of the specific site you want to search. Can someone modify this for me, to search specific geocities sites? Thanks for your help and btw I'm using Mozilla Suite and Firefox. ...
3
2949
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
2916
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 fewer than 80 characters. It then prompts the user to type the search-substring of 10 or fewer characters. Finally, it prompts the user to type the replace-substring of 10 or fewer characters. The second function call is the search-and-replace...
3
1918
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 know what to search for), but heres the problem: I am making a search function for my website, i want this to be possible: - search for 1 keyword (the problem guy) - search for multiple keywords things that alreaddy work (so no problem with...
0
10794
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 inside an image, hide your complete image as text ,search for a particular image inside a directory, minimize the size of the image. However this is not a new concept, there is a concept called Steganography which enables to conceal your secret...
0
9658
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10824
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10579
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
9362
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6975
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5644
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4443
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
2
4003
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3103
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.