note 61486 modified in language.functions by levim
| From: | levim@php.net | Date: | Sun, 07 Jul 2013 18:42:46 +0000 |
| Subject: | note 61486 modified in language.functions by levim | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-195486@lists.php.net to get a copy of this message | ||
This is a way of formatting different strings with different mandatory functions and is especially
useful when processing form data or outputting database fields using structured configuration files:
<?php
function format_string($string,$functions) {
$funcs = explode(",",$functions);
foreach ($funcs as $func) {
if (function_exists($func)) {
$string = $func($string);
}
}
return $string;
}
echo format_string(" <b> this is a test </b>",
"strip_tags,strtoupper,trim");
// outputs "THIS IS A TEST"
?>
--was--
This is a way of formatting different strings with different mandatory functions and is especially
useful when processing form data or outputting database fields using structured configuration files:
<?
function format_string($string,$functions)
{
$funcs = explode(",",$functions);
foreach ($funcs as $func)
{
if (function_exists($func)) $string = $func($string);
}
return $string;
}
echo format_string(" <b> this is a test
</b>","strip_tags,strtoupper,trim");
// outputs "THIS IS A TEST"
?>
http://php.net/manual/en/language.functions.php