1

Hello I have question as I having issue to find a solution that works

basically in my string I have text like

anim(10, <-0.016, -0.006, 0.217>, <0.000, 0.000, 0.707, 0.707>, <0.016, 0.010, 0.012>);

what I looking to achieve it to break down this into array

something like

array(
0 => 'anim',
1 =>  '10',
2 => '<-0.016, -0.006, 0.217>',
3 => '<0.000, 0.000, 0.707, 0.707>',
4 => '<0.016, 0.010, 0.012>'
);

so I can prepare the data to send back to another script that will use it as I have special functions to make it easier for users to use.

hope someone can help as far as I managed to to break down this into 2 arrays but I need them on each line of array so I can run loops to prepare the data

Stephen

2 Answers 2

3

You can use this regex in preg_match_all:

(<[^>]*>|\w+)

Code:

$re = '/(<[^>]*>|\w+)/'; 
$str = "anim(10, <-0.016, -0.006, 0.217>, <0.000, 0.000, 0.707, 0.707>, <0.016, 0.010, 0.012>);"; 

preg_match_all($re, $str, $matches);

RegEx Demo

Sign up to request clarification or add additional context in comments.

2 Comments

also I do have other methods I will look how you did this do I need to have separate regex for each api like I have others like texture(9,-1,389d95a3-280a-474a-1349-514f21dc20b8) or can they all be done in one regex and put the arrays for for all of them
I believe you can use /(<[^>]*>|[\w-]+)/ regex for both cases.
2

You can use the following regex.

preg_match_all('/<[^>]*>|\w+/', $str, $matches);
print_r($matches[0]);

Output

Array
(
    [0] => anim
    [1] => 10
    [2] => <-0.016, -0.006, 0.217>
    [3] => <0.000, 0.000, 0.707, 0.707>
    [4] => <0.016, 0.010, 0.012>
)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.