[Solved] Replace “//” with “/* */” in PHP? [closed]


First, as was pointed out in the comments, if you’re looking to reduce the size, comments should be stripped.

function convertComment(str){
   if(str.substring(0,2) === '//'){
       str="/*" + str.substring(2) + ' */';
   } else {
       str = false;
   }
   return str;
}

Your example code looked like JQuery, so if you were looking for PHP, here is that version:

function convertComment($s){
   if(substr($s,0,2) == '//'){
       $s="/*" . substr($s,2) . ' */';
   } else {
       $s = false;
   }
   return $s;
}

7

solved Replace “//” with “/* */” in PHP? [closed]