Hello
I need to extract some bits of information from a web page, so
I used preg_match_all. I was wondering if there's a simpler algorithm,
or if that's the way it's done:
===========
preg_match_all("|$regex|smi",$buffer,$matches,PREG _PATTERN_ORDER);
$elements=sizeof($matches);
$x=sizeof($matches,TRUE);
$rows = $x/$elements;
$rows--; //Why is the last row empty?
print "elements=$elements, x=$x, $rows<br>";
for ($row=0;$row < $rows;$row++){
$string = "";
for($element=1;$element < $elements;$element++){
$string .= $matches[$element][$row] . ",";
}
//Remove trailing ","
$string = trim($string, ",");
print "$string<hr>";
}
===========
Thank you. 2 1284
On 12.06.2007 20:37 Gilles Ganault wrote:
Hello
I need to extract some bits of information from a web page, so
I used preg_match_all. I was wondering if there's a simpler algorithm,
or if that's the way it's done:
===========
preg_match_all("|$regex|smi",$buffer,$matches,PREG _PATTERN_ORDER);
$elements=sizeof($matches);
$x=sizeof($matches,TRUE);
$rows = $x/$elements;
$rows--; //Why is the last row empty?
print "elements=$elements, x=$x, $rows<br>";
for ($row=0;$row < $rows;$row++){
$string = "";
for($element=1;$element < $elements;$element++){
$string .= $matches[$element][$row] . ",";
}
//Remove trailing ","
$string = trim($string, ",");
print "$string<hr>";
}
===========
Thank you.
Try using foreach to iterate through your arrays.
--
gosha bine
extended php parser ~ http://code.google.com/p/pihipi
blok ~ http://www.tagarga.com/blok
On Wed, 13 Jun 2007 10:45:48 +0200, gosha bine <st********@gmail.com>
wrote:
>Try using foreach to iterate through your arrays.
I'll try it. Thanks. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Han |
last post by:
I'm wondering if someone can explain why the following works with
preg_match_all, but not preg_match:
$html = "product=3456789&"
preg_match_all ("|product=(\d{5,10})&|i", $html, $out);
$out...
|
by: Han |
last post by:
I know this is possible (because preg can do almost anything!), but can't
get a handle on the syntax.
I have an HTML string:
<font size="3"><a...
|
by: Han |
last post by:
The following pattern (which is one subpattern in a string of several) looks
for the following
$xxx,xxx.xx (with the dollar sign)
or
xxx,xxx.xx (space in replace of missing dollar sign)
...
|
by: petrovitch |
last post by:
While using the following loop to extract images from the google search
engine I discovered that preg_match_all works much faster parsing small
strings in a loop than extracting all of the urls at...
|
by: Fabian |
last post by:
Hi all there,
I have already tried asking for help a couple of days ago.
I try to rephrase better my problem:
I need to grab a webpage that looks like this:
<td width=80 align=center...
|
by: greatprovider |
last post by:
i'm starting with a string such as "Na**3C**6H**5O**7*2H**20"
im attempting to match all **\d+ ...once i can match all the double
asterix \d i intend to wrap the \d in "<sub>" tags for display...
|
by: ngmr80 |
last post by:
Hi,
I'm experiencing a problem when trying to capture substrings with
preg_match_all() from strings like
"set('Hello','World')"
using the following Regular Expression (PERL syntax):
...
|
by: PaulB |
last post by:
Hello, as a newbie I'm requesting some help in understanding the regular
expression below
preg_match_all("|<tr(.*)</tr>|U",$table,$rows);
Would anybody please just run through...
|
by: loriann |
last post by:
hi,
I have a problem with preg_match function returning empty arrays for my wonderful regexes. However, I can't see what I am doing wrong - maybe one of you could help?
I'm loading the source...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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...
|
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...
| |