Jump to content

Alhazred

New Members
  • Posts

    2
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Alhazred's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I've got a several strings like these: Firstname1 Lastname1 (13) reported contact (0.06) with another vehicle Firstname2 Lastname2 (37) Firstname3 Lastname3 (45) reported contact (0.03) with another vehicle Firstname4 Lastname4 (54) Firstname5 Lastname5 (42) reported contact (0.42) with another vehicle Firstname6 Lastname6 (22) What I need to do is to create an array like this: array( array( Name => "Firstname1 Lastname1", Type => "reported contact with another vehicle Firstname2 Lastname2", Intensity => 0.06 ), array( Name => "Firstname3 Lastname3", Type => "reported contact with another vehicle Firstname4 Lastname4", Intensity => 0.03 ), array( Name => "Firstname5 Lastname5", Type => "reported contact with another vehicle Firstname6 Lastname6", Intensity => 0.42 ) ); I'm taking the first names in this way inside a foreach loop (strings come from an XML file) preg_match('/(.*?)\(/', $incident, $name); but with "echo $name[0]" I get "Firstname1 Lastname1 (" so I also get the ( which I don't want, but I have use it in the regex pattern as a marker The same thing happen when I use preg_match('/\)(.*?)\(/', $incident, $type); to take the first part of the incident description echo $type[0] prints ") reported contact (" and I don't want the ) and ( How do I have to do to get only the parts which I need?
×
×
  • 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.