note 86835 modified in function.sprintf by danbrown

From: Date: Wed, 05 Nov 2008 21:41:09 +0000
Subject: note 86835 modified in function.sprintf by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-146187@lists.php.net to get a copy of this message
<?php // parses a string meant for printf and returns an array of found parameters (or NULL if it contains syntax errors) function parsePrintfParameters($string) { $valid = '/^(?:%%|%(?:[0-9]+\$)?[+-]?(?:[ 0]|\'.)?-?[0-9]*(?:\.[0-9]+)?[bcdeufFosxX])/'; $originalString = $string; $result = array(); while(strlen($string)) { if(!$string = preg_replace('/^[^%]*/', '', $string)) break; if(preg_match($valid, $string, $matches)) { $result[] = $matches[0]; $string = substr($string, strlen($matches[0])); } else { error(sprintf('"%s" has an error near "%s".', $originalString, $string)); return NULL; } } return $result; } ?> --was-- <? // parses a string meant for printf and returns an array of found parameters (or NULL if it contains syntax errors) function parsePrintfParameters($string) { $valid = '/^(?:%%|%(?:[0-9]+\$)?[+-]?(?:[ 0]|\'.)?-?[0-9]*(?:\.[0-9]+)?[bcdeufFosxX])/'; $originalString = $string; $result = array(); while(strlen($string)) { if(!$string = preg_replace('/^[^%]*/', '', $string)) break; if(preg_match($valid, $string, $matches)) { $result[] = $matches[0]; $string = substr($string, strlen($matches[0])); } else { error(sprintf('"%s" has an error near "%s".', $originalString, $string)); return NULL; } } return $result; } ?> http://php.net/manual/en/function.sprintf.php

« previous php.notes (#146187) next »