PHP program which extracts attribute list from the custom tag. It also strips out the single and double quote if it exists around attribute value. <?phpfunction parseAnswerTag($tag){    // input => <answer scale=10 points=7>    // ouput => [scale=>10, points=>7]    // get the answer tag and parse out the attributes of answer tag    $returningObj = array();    //get the splitted string as an array    $arr = splitByDelimiter(array('delimiter' =>  , 'string'=> $tag));    // sliced the array to just have attributes otherwise will have answer element too    foreach (array_slice($arr, 1) as $key => $value)    {        $arr[$key] = splitByDelimiter(array('delimiter' => =, 'string'=> $value));         if(in_array('scale', $arr[$key]) or in_array('points', $arr[$key]))        {            // check to see if single or double quote exist in value of key            if(preg_match(/['\]/,$arr[$key][1]))            {                // makes a call to strip out the quotes                $returningObj[$arr[$key][0]] = stripQuotes($arr[$key][1]);             }        }    }    // returns the associate key of attribute in the tag    return $returningObj;}function stripQuotes($str){    // input => 10    // output => 10    // gets attribute with value and returns unquote string    var_dump(strpos($str, ') === FALSE);    $start_point = 0;    $end_point = 0;    if(strpos($str, ') !== FALSE)    {        $start_point = strpos($str, ');        $end_point = strpos($str, ', $start_point+1);    }    elseif (strpos($str, '') !== FALSE)     {        $start_point = strpos($str, '');        $end_point = strpos($str, '', $start_point+1);    }    return substr($str, $start_point+1, $end_point - ($start_point+1));} function splitByDelimiter($input){    //gets a associate array with delimiter and string {text value to be splitted}, split them by passed delimiter and return them    // $input['delimiter'] => value splitted by and $input['string'] => value to be splitted    return explode($input['delimiter'], $input['string']);}Can you please give me some constructive suggestions so that I can improve?
PHP program which extracts attribute lists from custom tag
php;php5
My function does not use hard-coded attributes, so it is more flexible than yours. It's also just a few lines of code (I think you made things over-complicated by having very thin wrappers for explode and trim.function parseAttributesFromTag($tag){    //The Regex pattern will match all instances of attribute=value    $pattern = '/(\w+)=[\']([^\']*)/';    //preg_match_all used with the PREG_SET_ORDER flag will build an array    //for each attribute-value pair present and put it in $matches. eg:    /* with tag <answer scale='10' points=23>    Array (        [0] =>(                [0] => scale='10                [1] => scale                [2] => 10              )        [1] => (                [0] => points=23                [1] => points                [2] => 23            )    )    */    preg_match_all($pattern,$tag,$matches,PREG_SET_ORDER);    $result = [];    foreach($matches as $match){        $attrName = $match[1];        //parse the string value into an integer if it's numeric,        // leave it as a string if it's not numeric,        $attrValue = is_numeric($match[2])? (int)$match[2]: trim($match[2]);        $result[$attrName] = $attrValue; //add match to results    }    return $result;}This will turn <tagname attr1=value1 attr2='value2'> into [attr1=>value1, attr2=>value2].  Unlike the other answer, this function supports spaces in attribute value and I have casted the value into a numeric type when it's really a number rather than a string