note 29091 deleted from ref.strings by tomsommer

From: Date: Wed, 15 Sep 2004 20:48:16 +0000
Subject: note 29091 deleted from ref.strings by tomsommer
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-76791@lists.php.net to get a copy of this message
Note Submitter: webmaster at gamequbed dot com ---- I was recently working on a template engine, and i found that i wanted to add parameters to my template includes, for example, {SUBJECTFIELD template="LINK_ROW" class="subjectfield"} I found that this code worked out quite well! It converts the string into $fileParam["SUBJECTFIELD"]["template"] which will print "LINK_ROW". It also works for multiple blocks. Have fun! $text = " {SUBJECTFIELD class=\"alternate\" rowtemplate=\"LINK_ROW\"} {BODYFIELD class=\"alternate2\" rowtemplate=\"LINK_ROW\"}"; ## remove quotes $text = str_replace("\"","",$text); ## set counter $counter = 0; for ($i=0;$i<strlen($text);$i++) { ## convert each {...} block into an array element if ($text[$i] == "{") { $currentEndBrace = strpos($text,"}"); $param[$counter] = substr($text,$i,$currentEndBrace); ## remove the end brace $text[$currentEndBrace] = ""; $counter++; } } $fileParam = array(); for ($j=0;$j<count($param);$j++) { ## remove trailing stuff $param[$j] = rtrim($param[$j]); ## and the braces $param[$j] = ereg_replace("{","",$param[$j]); $param[$j] = ereg_replace("}","",$param[$j]); ## get the name of the template $tempIdent = substr($param[$j],0,strpos($param[$j]," ")); ## get the rest of the vars $param[$j] = substr($param[$j],strpos($param[$j]," ")+1); ## make a new array $fileParam[$tempIdent] = $param[$j]; } while(list($key,$val) = each($fileParam)) { ## set up as a query string $val = str_replace(" ","&",$val); ## parse it to a new array parse_str($val,$eachVal); ## and assign it to another array $fileParam[$key] = $eachVal; }

« previous php.notes (#76791) next »