sprintf scientific number ejemplo c# php

scientific - C#String.Format() Equivalente en PHP?



string.format c# ejemplo (2)

Podrías usar la función sprintf :

$filter = "content:%1$s title:%1$s^4.0 path.title:%1$s^4.0 description:%1$s ..."; $filter = sprintf($filter, "Cheese");

O escribe tu propia función para reemplazar { i } por el argumento correspondiente:

function format() { $args = func_get_args(); if (count($args) == 0) { return; } if (count($args) == 1) { return $args[0]; } $str = array_shift($args); $str = preg_replace_callback(''///{(0|[1-9]//d*)//}/'', create_function(''$match'', ''$args = ''.var_export($args, true).''; return isset($args[$match[1]]) ? $args[$match[1]] : $match[0];''), $str); return $str; }

Estoy construyendo una expresión de búsqueda Lucene.NET bastante grande. ¿Hay alguna forma recomendada de hacer el reemplazo de cadenas en PHP? No tiene que ser así, pero estoy esperando algo similar al método de C # String.Format.

Así es como se vería la lógica en C #.

var filter = "content:{0} title:{0}^4.0 path.title:{0}^4.0 description:{0} ..."; filter = String.Format(filter, "Cheese");

¿Hay un equivalente de PHP5?