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

Help req: PHP and pattern matching.

Despite looking at a number of tutorials in books and online examples on
pattern matching - I can't quite get my head around it to work... so need
some help.

What I have now is a variable that is POST'ed to a PHP script and I want
the script to go through a database to search through to check if a certain
value is entered in a field, if yes - echo the entire row, if not, move
onto the next record to check.

So far I have managed to write a script that would search each record in
turn of the database - but need something to perform a pattern match. I
have seen a function called preg_grep() but there are no really good
examples, especially on how to construct a pattern search term in the
first place.

Back to the problem, the POST to the PHP script would have a value of say
"video", but the database could have values for that field of "video021" or
"audio005" or "screensaver010" etc.. (file type and file number).

So I need to match the first part of the file ID (and exclude the file
number, ie. "video" and not "video021")... then echo the row each time the
script found a match for "video" and move onto the next row for other
instances of "video" to echo.

Any help appreciated.

Dariusz
Jul 17 '05 #1
1 2024
On Sun, 07 Mar 2004 10:07:41 +0000, Dariusz wrote:
Back to the problem, the POST to the PHP script would have a value of
say "video", but the database could have values for that field of
"video021" or "audio005" or "screensaver010" etc.. (file type and file
number).

So I need to match the first part of the file ID (and exclude the file
number, ie. "video" and not "video021")... then echo the row each time
the script found a match for "video" and move onto the next row for
other instances of "video" to echo.


Using MySQL? IMHO it's better to leave this to the db-engine...

SELECT ID, field_1 FROM video_tbl WHERE ID LIKE '%video%';

Also check the MySQL manual for Fulltext for a more "search engine like"
functionality.

--
mvh/regards
Joachim Mæland

If everything seems under control, you're just not going fast enough.
-Mario Andretti

Jul 17 '05 #2

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

Similar topics

9
by: Xah Lee | last post by:
# -*- coding: utf-8 -*- # Python # Matching string patterns # # Sometimes you want to know if a string is of # particular pattern. Let's say in your website # you have converted all images...
1
by: Henry | last post by:
I have a table that stores a list of zip codes using a varchar column type, and I need to perform some string prefix pattern matching search. Let's say that I have the columns: 94000-1235 94001...
10
by: bpontius | last post by:
The GES Algorithm A Surprisingly Simple Algorithm for Parallel Pattern Matching "Partially because the best algorithms presented in the literature are difficult to understand and to implement,...
2
by: Mortimer Schnurd | last post by:
Hi All, I am a VB 6 programmer who is now trying to learn C#. In doing so, I am trying to convert some of my VB modules to C#. I routinely user Reg Expressions in VB and am having some trouble...
1
by: Rahul | last post by:
Hi Everybody I have some problem in my script. please help me. This is script file. I have one *.inq file. I want run this script in XML files. But this script errors shows . If u want i am...
2
by: Ole Nielsby | last post by:
First, bear with my xpost. This goes to comp.lang.c++ comp.lang.functional with follow-up to comp.lang.c++ - I want to discuss an aspect of using C++ to implement a functional language, and...
0
by: shrik | last post by:
I have following error : Total giant files in replay configuration file are : File name : /new_file/prob1.rec Given file /new_file/prob1.rec is successfully verified. Splitting for giant file...
5
by: pramodkh | last post by:
Hi All I am trying to match a pattern in a file and insert a line. If the pattern matches then insert a line before the matching pattern line. for example, I have the following content in a...
9
by: Simon Woods | last post by:
Hi I'm new to Regular Expressions so ... I trying to work out regular expressions to parse the following (a + (b + c)) I really want to replace it with
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
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
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,...

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.