hello i am trying to do something like this in php i have a variable in my db that is formated like this $myvariable=a4.500012b74.35666|a5.7545b5.3261|a54.32b36.221 the string will have diffrent lenght at diffrent times in another word i do not know how many pairs of info iare there i want to break this up and have a list of the pairs in xml <point a="4.500012" b="74.35666" /> <point a="5.7545" b="5.3261" /> <point a="54.32" b="36.221" /> PHP:
Try using the 'explode' function for '|'. This will put your points in an array. You will then can loop through your array and truncate your string.
Slightly more than a couple of lines... $myvariable="a4.500012b74.35666|a5.7545b5.3261|a54.32b36.221"; $exp = explode("|",$myvariable); foreach ($exp as $var) { $out = explode("b",$var); $output_1 = str_replace("a","",$out[0]); $output_2 = $out[1]; echo "<point a=\"" . $output_1 . "\" b=\"" . $output_2 . "\" />\n"; } PHP: