Jump to content

I used $locarray = preg_split($wordstring, -1, PREG_SPLIT_OFFSET_CAPTURE); cant


josheeg

Recommended Posts

I used $locarray = preg_split($wordstring, -1, PREG_SPLIT_OFFSET_CAPTURE); to devide a string up... now the offset of the words that it split up is important I can see it by using print_r like this...

print_r($locarray);

 

Then I get back this...

Array ( [0] => Array ( [0] => [1] => 0 ) [1] => Array ( [0] => The [1] => 1 ) [2] => Array ( [0] => adventure's [1] => 5 ) [3] => Array ( [0] => not [1] => 17 ) [4] => Array ( [0] => over [1] => 21 ) [5] => Array ( [0] => yet! [1] => 26 ) [6] => Array ( [0] => All-new [1] => 31 ) [7] => Array ( [0] => episodes [1] => 39 ) [8] => Array ( [0] => of [1] => 48 ) [9] => Array ( [0] => Stargate [1] => 51 ) [10] => Array ( [0] => SG-1 [1] => 60 ) [11] => Array ( [0] => are [1] => 65 ) [12] => Array ( [0] => coming [1] => 69 ) [13] => Array ( [0] => in==2007 [1] => 76 ) [14] => Array ( [0] => as [1] => 86 ) [15] => Array ( [0] => the [1] => 89 ) [16] => Array ( [0] => team [1] => 93 ) [17] => Array ( [0] => faces [1] => 98 ) [18] => Array ( [0] => its [1] => 104 ) [19] => Array ( [0] => greatest [1] => 108 ) [20] => Array ( [0] => challenge: [1] => 117 ) [21] => Array ( [0] => stopping==the [1] => 128 ) [22] => Array ( [0] => Ori [1] => 142 ) [23] => Array ( [0] => invasion [1] => 146 ) [24] => Array ( [0] => of [1] => 155 ) [25] => Array ( [0] => the [1] => 158 ) [26] => Array ( [0] => Milky [1] => 162 ) [27] => Array ( [0] => Way [1] => 168 ) [28] => Array ( [0] => galaxy!== [1] => 172 ) )

 

How do I get the offsets to show up individually I can't seem to acsess them and $test=$locarray[0][0]; does not print out something but 01 does print out a 0...

please help

 

 

Link to comment
Share on other sites

The formatting there is quite weird.  But the array looks normal.  You should be able to access it like this:

 

foreach ($locarray as $l) {
  print "-{$l[0]}- at offset {$l[1]}\n";
}

 

$locarray[0][0] prints nothing out because the element there is an empty string.  [0][0] is the first string, [0][1] the first offset, [1][0] the second string, [1][1] the second offset, etc etc

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.