I'm wondering if any coders out there can take a look at this code and tell me if it's "safe" -- it works, but for all I know I could be using up tons of resources or something.

What it does: using the textimage module, this code auto-replaces all node titles with a fancy graphical title, and will split the title onto two lines if it exceeds a certain length. It also attemps to clean up the title a bit so the graphics are named safely in unix.

		$fullttl = $title;
        if ($title) {
        	$title = ereg_replace('\?', '', $title); // replace bad characters
        	$title = ereg_replace('\,', '', $title); // replace bad characters
        	$title = ereg_replace('\#', 'No.', $title); // replace bad characters
        	$title = ereg_replace('\$', '', $title); // replace bad characters
        	$title = ereg_replace('\'', '', $title); // replace bad characters
        	$title = ereg_replace('\/', '-', $title); // substitute forward slashes with dash
        	$title = ereg_replace(' ', '_', $title); // replace spaces with underscores
        	$cut = '55'; // max line length
        	if (strlen($title) > $cut) {
        		while (!preg_match("/_/", $title[$cut])) {
        			$cut++;
        			if (!$title[$cut]) {
						break;
    				}
        		}
        		$title1 = substr($title, 0, $cut+1);
        		$title2 = substr($title, $cut+1, strlen($title));
        		print "<img src = '/path_to_files_dir/textimage/preset_name/$title1.jpg' title = '$fullttl' alt = '$fullttl'><br>";
				print "<img src = '/path_to_files_dir/textimage/preset_name/$title2.jpg' title = '$fullttl' alt = '$fullttl'>";
           	} else {
        	print "<img src = '/path_to_files_dir/textimage/preset_name/$title.jpg' title = '$fullttl' alt = '$fullttl'>";
        	}
        }

The above code is placed in your theme's page.tpl.php file, replacing the existing $title code.

path_to_files_dir == the path to your installation's files directory
preset_name == the name of the preset you've set up in the textimage module

Any glaring errors? Or perhaps a way to simplify the code?