% This must be changed to suit your machine (including / vs \)!
current_dir = 'C:\Users\ben-user\Documents\MATLAB\web_final\';

% build-system slash
slash='\'; % Windows (non-escaped)

% web-server-system slash (escaped where relevant)
sslash='/'; % unix - works on Apache under windows though

str_nav='"includes/navigation.php"'; % navigation string in xsl file
parent = ['..' sslash];
nav = ['includes' sslash 'navigation.php'];
nav_course =[parent nav];
nav_page = [parent parent nav];


[rest,filename]=fileparts(pwd);
year=rest((end-1):end);



fprintf(['Publishing ' filename '.m\n']);
    publish( [filename '.m'], struct('outputDir', [current_dir year slash filename slash],'figureSnapMethod','getframe'));
    copyfile([filename '.html'], [filename '.php']);
    fid = fopen([filename '.html'], 'r');
    fod = fopen([filename '.php'], 'w');
    while ( ~feof(fid) )
        s = fgetl(fid);
        s = strrep(s, str_nav, ['"' nav_page '"']);
        fprintf(fod, '%s\n', s);
    end
    fclose(fid);
    fclose(fod);
    delete([filename '.html']);
    close all force;
    fprintf('Success!\n');