473,799 Members | 3,025 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PREG search for multiple values in one pass?

I am trying to do a search through some data, more specifically HTML,
to extract data from it. So for example I may have:

<b>Title:</b<em>This is a title</em>
<b>Name:</b<em>Fred</em>

I wish to grab the data "This is a title" and "Fred" against their
corresponding headings in an array (e.g. $array[title] = "This is a
title") .... but the key doesn't matter, that need not come from the
regexp but I can do manually.

The question is - how do I do this in one pass? Do I just use use
nested OR's in my regexp? The problem with this though, is once a match
is made, how does PHP then tell me what it corresponds to if it's an
OR? (it just returns the match surely?)

Actually i'm not even too sure how to go about doing this... do I need
backreferencing etc...? I've read the php.net pages but couldn't
entirely make sense of the various preg functions.

Thanks a bunch!

Terence

Aug 19 '06 #1
1 1966
*** te************@ gmail.com escribió/wrote (18 Aug 2006 18:46:28 -0700):
I wish to grab the data "This is a title" and "Fred" against their
corresponding headings in an array (e.g. $array[title] = "This is a
title") .... but the key doesn't matter, that need not come from the
regexp but I can do manually.

The question is - how do I do this in one pass?

I'm unsure about your exact needs, but I hope this code helps:
$text='<b>Title :</b<em>This is a title</em>
<b>Name:</b<em>Fred</em>';

if(preg_match_a ll('@<b>(.*)</b>.*<em>(.*)</em>@Ui', $text, $matches)>0){
print_r($matche s);
}
This prints:

Array
(
[0] =Array
(
[0] =<b>Title:</b<em>This is a title</em>
[1] =<b>Name:</b<em>Fred</em>
)

[1] =Array
(
[0] =Title:
[1] =Name:
)

[2] =Array
(
[0] =This is a title
[1] =Fred
)

)
If keys don't matter, must ignore them: '@<b>.*</b>.*<em>(.*)</em>@Ui'

--
-+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
++ Mi sitio sobre programación web: http://bits.demogracia.com
+- Mi web de humor con rayos UVA: http://www.demogracia.com
--
Aug 19 '06 #2

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

Similar topics

2
10650
by: scott | last post by:
Hi, I'm having some trouble with something that should be relatively easy. I want to update multiple rows in one of my database tables simultaneously. In my table I have these values: imageID image_order I want to be able to modify the image_order column where imageID = imageID.
17
2448
by: Andrae Muys | last post by:
Found myself needing serialised access to a shared generator from multiple threads. Came up with the following def serialise(gen): lock = threading.Lock() while 1: lock.acquire() try: next = gen.next() finally:
4
2580
by: cwwilly | last post by:
Hello, Thanks for taking a look at this! Problem: I'm trying to pass multiple dynamic values between a slaveform and a masterform. The problem I'm having is on the slaveform I loop through multiple records and want two values depending on the row they select. slaveform: x=selected
5
2251
by: Homer Simpson | last post by:
Hi All, I'm trying to write a method where I pass three arguments and the method returns six values. All the values will be doubles. First, is it possible to get multiple values returned by a method? Second, how do I do it? I know how to write the method, pass arguments to it and get a single value returned but how do I pass multiple values back? Last, how do I reference the various values returned? I assume there is some array used...
32
14905
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if ((someString.IndexOf("something1",0) >= 0) || ((someString.IndexOf("something2",0) >= 0) ||
1
7131
by: dan_williams | last post by:
Is it possible to pass multiple discrete values to a report document so that I can export it to PDF? I've managed to perform the following code to display a Crystal Report Viewer ok, but i want to be able to export that to a PDF and print it. Dim invNos As New ArrayList -- populated elsewhere in my code. Dim oRpt As New ReportDocument oRpt.Load(MapPath(<crystalReport>))
8
5210
by: aleksandar.ristovski | last post by:
Hello all, I have been thinking about a possible extension to C/C++ syntax. The current syntax allows declaring a function that returns a value: int foo(); however, if I were to return more than one value, for example three int-s, I would have to change my "logic" and pass the references to my
23
9076
blyxx86
by: blyxx86 | last post by:
I am trying to filter multiple entries with only one search box. That way the user can type whatever they want and find all the values that contain what they enter. Private Sub txtLookup_AfterUpdate() Me.Filter = " Like '*" & & "*'" OR " Like '*" & & "*'" Me.FilterOn = True End Sub It allows for variables and to filter within the form. I can't seem to find a way to make it actually search through multiple fields (Serial,...
3
2277
moishy
by: moishy | last post by:
If I wanted to match for instance, all characters that are not in <TAGS>, I would search for all ">ANYTHING<". But how do I make that "ANYTHING"? What will be the PREG for absolutely ANY characer? (except ">" and "<")
0
9688
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10268
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10247
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
10031
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9079
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
6809
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
5593
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4146
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
3
2941
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.