Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Accessing preg_split arrays ... ?

Status
Not open for further replies.

dbeezzz

Technical User
Nov 30, 2005
54
KR
So I'm trying to take out all the text in my html page between the elements of <!-- START_CAPTURE_1 --> and <!-- END_CAPTURE_1 -->

So far I'm using a preg_split.
Code:
$start = preg_split("/<!-- START_CAPTURE_1 -->/", $html_page_text, -1, PREG_SPLIT_OFFSET_CAPTURE);

$end = preg_split("/<!-- END_CAPTURE_1 -->/", $html_page_text, -1, PREG_SPLIT_OFFSET_CAPTURE);
... this gives me a series of arrays, which I'm trying to access and then do a simple index subtraction to find all the text between my two CAPTURE elements. Then I'll probably use stristr to parse out the text in the middle.

I'm having a problem with accessing the arrays within the $start and $end arrays though. The $start array is given back to me as
Code:
array(2) { 
      [0]=>  array(2) { 
            [0]=>  string(0) "" [1]=>  int(0) } 
            [1]=>  array(2) { 
                   [0]=>  string(56) "HTML_TEXT_THAT_I_WANT"                                      [1]=> int(34) 
   } 
}
... but I'm having a simple problem in accessing the second element of the second array ie. the value 34.
I've tried the obvious $start[1].Array[2] but no luck. What's the name of that second array ?

I guess I could try to access each element in turn with two for loops, but I'd rather not have to. Anyone any ideas ?

Also, is there an easier way to do this whole thing ? I can't find any php function that suits my needs exactly. Am I missing something ?
 
Cool, I can access the array as $start[1][1].

I was also looking at thenewa2x's post below, and he's encountering a similar problem. I'll have a further look at his solution and post back with any problems.

I'm not really sure which method would be more efficient. I know regex's are hard on the system resources. I'm assuming this method would be the faster of the two, since the regex would be less complicated than doing a full regex to search through the html sheet for all the values fitting an exact regex. My assumptions may be incorrect though.

Any thoughts ?
 
there may be easier ways. can the tags be nested? and is it always the same tag pair?

i think i posted a non-regex solution for nested tags a few weeks ago.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top