You are here: define function dynamically « All PHP « IT news, forums, messages
define function dynamically

Posted by Ridge Burner on 05/19/06 17:40

I have seen this done before, but I can't remember the specifics nor any
keywords really to Google it. Hopefully someone can point me in the right
direction.

I want to use a parameter in custom function to determine what pre-defined
function to call to manipulate some text.

<?php
$string = "hello world";

function change_text($string,$mode='NORMAL'){
if($mode != 'NORMAL'){
return $mode($string); //$mode should become the name of
the function I want to call to manipulate the text
}else{
return $string;
}
}

//Some examples of what I want
echo change_text($string); // return hello world
echo change_text($string,'ucwords'); // return Hello World
echo change_text($string,'strtoupper'); // return HELLO WORLD
echo change_text($string,'strtolower'); // return hello world
echo change_text($string,'ucfirst'); // return Hello world
?>


Thanks in advance for any help you can offer!

--Ridge

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация