Simple function not working
Posted: Thu Oct 18, 2007 8:41 pm
feyd | Please use
Thanks in advance for your help.
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I am trying to build a larger function but find I am failing miserably at the basics of creating a simple one.
The core function is used to replace some text in a string. Although the replace function inside checks out when used independently, the created function simply returns nothing.Code: Select all
<?
@$original_text="AB";
@$newtext="";
//
function translate($text) {
$newtext= str_replace('A','C',$text);
return $newtext;}
//
translate($original_text); //call the function
echo $newtext . '<br>'; //display translated text
echo "should return CB";
?>feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]