kelphyr Posted February 19, 2007 Share Posted February 19, 2007 Like if I have a line like this: 501,Red_Potion,Red Potion,0,50,,70,,,,,0xFFFFFFFF,7,2,,,,,,{ itemheal rand(45,65),0; },{},{} list($script,$equip,$unequip) = explode("...", $line); ... = { get the stuff here inbetween } so instead of being one symbol the first one is { then } then { then }.... does that make sense? i need to get the 3 inbetween {} {} {} Link to comment https://forums.phpfreaks.com/topic/39120-is-there-any-way-to-use-explode-like-this/ Share on other sites More sharing options...
btherl Posted February 19, 2007 Share Posted February 19, 2007 explode() isn't that smart unfortunately. Actually I don't think any php functions can handle that sort of csv data easily. If you know the three {} are always at the end, you can chop those ones off and deal with them specially. That might be the best way to go about it. You can explode() them on '{', and then find and remove the trailing '}' with str_replace(). The earlier data looks like it can be split safely on ',' Link to comment https://forums.phpfreaks.com/topic/39120-is-there-any-way-to-use-explode-like-this/#findComment-188433 Share on other sites More sharing options...
effigy Posted February 19, 2007 Share Posted February 19, 2007 <pre> <?php $data = '501,Red_Potion,Red Potion,0,50,,70,,,,,0xFFFFFFFF,7,2,,,,,,{ itemheal rand(45,65),0; },{},{}'; preg_match_all('/(?<=\{)[^}]*/', $data, $matches); print_r($matches); ?> </pre> Link to comment https://forums.phpfreaks.com/topic/39120-is-there-any-way-to-use-explode-like-this/#findComment-188648 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.