Jump to content

imperimus

New Members
  • Posts

    2
  • Joined

  • Last visited

imperimus's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. With a little help I have ended up with the following Function: function process_objects($data){ $pattern = "/<==OBJECTSTART==>.*?<==OBJECTEND==>/"; preg_match_all($pattern, $data, $objects); if(!empty($objects[0])){ foreach($objects as $objectarr){ foreach($objectarr as $object){ $line = preg_replace('/<==OBJECTSTART==>(.*)<==OBJECTEND==>/', '\1', $object); $pairs = explode(',', $line); $new_data = array(); foreach ($pairs as $pair) { list ($key, $value) = explode('=>', $pair); $new_data[$key] = $value; } $replacement = get_object($new_data[type],$new_data[objectid],$new_data[options]); $data = str_replace($object, $replacement, $data); } } // return $data; } } function get_object($objtype, $objid, $objoptions){ $item = "<table><tr><td>this is an object: ".$objtype."</td></tr></table>\n"; return $item; } Seems to work, but not sure if it is the most efficient way to get there!
  2. Hi Folks, Been getting into a little coding recently and trying to parse some templates that will need embedded objects found and processed in order to generate the output. I have the following string which I need to be bale to extract the parameters from in order to process the next part of the code. I have manage to do this by doing multiple preg_match_all, but it is not very efficient and/or dynamic. Example strings (the source might contain multiples): <==OBJECTSTART==>type=>sqltable,objectid=>4000001,options=>1|5|2<==OBJECTEND==> <==OBJECTSTART==>type=>sqltable,objectid=>4000002,options=>3|8|5<==OBJECTEND==> What I have so far I have go to the following for a regex expression: /<==OBJECTSTART==>((.?),)(.?)<==OBJECTEND==>/ This gives me the information before the first comma but I have tried the usual + and * to give me a repeat iteration but no luck. ideally I am looking for an array of objects that looks like the following [0]=> [type]=sqltable [objected]=4000001 [options]=1|5|2 [1]=> [type]=sqltable [objected]=4000002 [options]=3|8|5 thanks in advance!
×
×
  • 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.