Jump to content

A question in regular expression


Roee

Recommended Posts

Hi,

 

I have a row in my table (mysql) which contains something like this:

{1,1,1},{2,2,2},{3,3,3},{4,4,4}

 

How do I use reg exp to get an array of:

$arr[0] = {1,1,1}

$arr[1] = {2,2,2}

$arr[2] = {3,3,3}

$arr[3] = {4,4,4}

 

?

 

And after getting this array, How do I split it to something like:

$a[0][0] = 1

$a[0][1] = 1

$a[0][2] = 1

$a[1][0] = 2

$a[1][1] = 2

$a[1][2] = 2

$a[2][0] = 3

$a[2][1] = 3

$a[2][2] = 3

$a[3][0] = 4

$a[3][1] = 4

$a[3][2] = 4

 

Thank you very much

Roee

Link to comment
https://forums.phpfreaks.com/topic/207873-a-question-in-regular-expression/
Share on other sites

$data = '{1,1,1},{2,2,2},{3,3,3},{4,4,4}';

$parts = explode('},{', $data);
$arr = array();
foreach($parts as $part)
{
    $part = str_replace(array('{','}'), '', $part);
    $bits = explode(',', $part);
    $arr[] = $bits;
}

echo '<pre>'.print_r($arr,true).'</pre>';

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.