Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

Convert huge if to functions

$
0
0

Hi Everyone,

 

I need help converting this if / ifelse to a function, (I am new), 

 

if($file_extension == 'unknown'){$doc_extension = 'unknown'; $file_type = 'Unknown';}
elseif(($fe=='docx')||($fe=='doc')||($fe=='docm')||($fe=='dotx')||($fe=='dotm')||($fe=='pages')||($fe=='wps')){$doc_extension='docx';$file_type='Word Document';}
elseif(($fe=='pdf')||($fe=='pdp')){$doc_extension='pdf';$file_type='PDF';}
elseif(($fe=='xlsx')||($fe=='xlsm')||($fe=='xlsb')||($fe=='xltx')||($fe=='xltm')||($fe=='xls')||($fe=='xlt')||($fe=='xls')||($fe=='csv')){$doc_extension='xlsx';$file_type='Excel Document';}
elseif(($fe=='zip')||($fe=='zipx')||($fe=='tar')||($fe=='gz')||($fe=='z')||($fe=='cab')||($fe=='rar')||($fe=='bz2')||($fe=='lzh')||($fe=='7z')||($fe=='img')||($fe=='iso')){$doc_extension='zip';$file_type='Zip Folder';}
elseif(($fe=='jpg')||($fe=='jpeg')||($fe=='jpe')){$doc_extension='jpg';$file_type='JPEG Image';}
elseif(($fe=='png')||($fe=='pns')){$doc_extension='jpg';$file_type='PNG Image';}
elseif(($fe=='gif')){$doc_extension='jpg';$file_type='GIF Image';}
elseif(($fe=='tiff')||($fe=='tif')){$doc_extension='jpg';$file_type='TIFF/TIF Image';}
elseif(($fe=='psb')||($fe=='bmp')||($fe=='rle')||($fe=='dib')||($fe=='eps')||($fe=='iff')||($fe=='tdi')||($fe=='jpf')||($fe=='jpx')||($fe=='jp2')||($fe=='j2c')||($fe=='j2k')||($fe=='jpc')||($fe=='jps')||($fe=='mpo')||($fe=='pcx')||($fe=='raw')||($fe=='pxr')||($fe=='pbm')||($fe=='ppm')||($fe=='pnm')||($fe=='pfm')||($fe=='pam')){$doc_extension='jpg';$file_type='Image File';}
elseif(($fe=='mp3')){$doc_extension='mp3';$file_type='MP3';}
else { $doc_extension = 'unknown'; $file_type = 'Unknown'; }
 
This goes on for 280lines... But If I get these done I will be able to do the rest, as you can see I am checking what the document file extension is from a database, $file_extension and depending the results, it creates a variable $doc_extension which works like this : class="$doc_extension" and this is a style from .style.css and it also changes  $file_type which is printed on the screen, This works fine as a large if/ifelse but I only had the index page of my application done now I am doing directories and every time I make a change to it all of it and it's way long process.
 
so what I want to do is just put <?php functionname();?> or <?php require 'fdsfas.php'; ?> so I can just change it once. 
 
If someone could please help that would be mad.
 
Thanks,
Brodey

Viewing all articles
Browse latest Browse all 13200

Trending Articles