Zend - The PHP Company




Text

Add Code


FUNCION PRINTFV (PRINT text with Format from a Variable)  

Type: application
Added by: Donatien
Entered: 25/01/2001
Last modified: 01/12/2000
Rating: - (fewer than 3 votes)
Views: 5044
This function prints out the contents of a varible replacing control codes ( \" \n \\ ) just like printf() does with a string literal.


<?PHP

// FUNCION PRINTFV (PRINT text with Format from a Variable)
// ( similar to PRINTF() )
// Author: Donatien
//
// This function prints out the contents of a varible 
// replacing control codes ( "  n  \ )
// just like printf() does with a string literal.


function printfv($Text)
{

$a "printf("{$Text}");";
eval(
$a);

}

?>


Usage Example


$text = "This text has "comillas" and a CR right here.n"
printfv($text);

// prints out a parsed string, just like:

printf("This text has "comillas" and a CR right here.n");

// but getting it from a variable instead of a string literal.

// and this is good because if we just run this:

$text = "This text has "comillas" and a CR right here.n"
printf($text);

// control codes will be printed without getting parsed.


Rate This Script





Search



This Category All Categories