php noob here trying to create a function but can't quite find the resource on the web that rids my confusions. Here it goes;

I want to create a function which takes a variable name, for example

Thief's Wit (4)

And converts it to 

thiefswit.jpg

So far, here is what I have
**THIS CODE IS LOADED TO TEST MY FUNCTION**

```
require_once 'functions.php';

$mod = "Thief's Wit (4)";
convertImage($mod);
echo $mod;
?>

```

**THIS CODE IS THE ACTUAL FUNCTION**

```
function convertImage($string)
{
$string = preg_replace('/\s+/', '', $string);
$string = str_replace("'", "", $string);
$stringlength = strlen($string);
substr ($string, 0, ($stringlength-4));
$string = strtolower ($string);
$string = "$string" . ".jpg";
return $string;
}
?>

```

The format of the strings will always be

NAME HERE (4)

which is why I substr the length-4.

When I run this function, it echoes the original string.

Any help here?
I'm new to PHP and don't really understand 

a) What the 'return' does at the end of the function and
b) Does the function inherently know to replace "$string" with the variable you tell it to act on in another file? In this case $mod.

Thanks!