Will Fris's WordPress Weblog











{20150810}   array_sprintf

Do you know of a quicker way to do this?
I’d be glad to know so šŸ™‚

The following code does a sprintf on a collection.


	if ( !function_exists( 'array_sprintf' ) ) {
		function array_sprintf ( $templateString , $inputArray ) {
			reset( $inputArray );
			while ( $i = each( $inputArray ) ) {
				if ( !is_array( $i[ 'value' ] ) ) {
					$i[ 'value' ] = array( $i[ 'value' ] );
				}
				array_unshift( $templateString , $i[ 'value' ] );
				$inputArray[ $i[ 'key' ] ] = call_user_func_array(
					'sprintf'
					, $i[ 'value' ]
				);
			}
			return $inputArray;
		}
	}

Obligatory example:


	$tags = array(
		array( 'href' => 'https://willfris.wordpress.com/' , 'txt' => 'This blog' )
		, [ 'http://willfris.nl/' , 'A site' ] # shorthand array-syntax
	);
	$element = [ '<li>' , '</li>' ];
	echo '<ul>' . $element[ 0 ]
		. implode(
			implode( $element )
			, array_sprintf( '<a href="%s">%s</a>' , $tags )
		)
		. $element[ 1 ] . '</ul>';
Advertisements


To make some comparison between CodeIgniter, CI from here on, and Symfony Framework, SF from here on, I decided to go through some of the first hits of Google for a change.

In general I can read in most posts that:
Both of the frameworks have superb documentation, which is very nice, thumbs up!

CI is nice and lightweight, while SF is nice and heavyweight
which just makes CI more responsive then SF
SF is all about best practises whereas CI seems to take a more pragmatic route
SF is in php5, CI can be in php4 _and_ php5
SF is mainly meant for big ass applications because of the way it is set up with a cli to create applications, modules, and what not more, while CI is more meant to be a great library with an easy to understand setup

I also read that CI has gotten a fork called Kohana a all php5-strict framework.
I will most certainly use this framework in a future project to get the feel of it.

I’ve started using Symfony now;
I wanted to have a InnoDB table (dunno why. :P) and I wanted it to be in utf8 charset and utf8_bin collation (dunno why. :S)
I found my InnoDB info here:
http://www.symfony-framework.com/2007/10/18/mysql-connection-configuration-schema-and-model-generation/
And the utf8 stuff can be found in chapter 8 of the symfony manual/book/or whatever.



et cetera