update page now

Voting

: three plus two?
(Example: nine)

The Note You're Voting On

razvan_bc at yahoo dot com
3 years ago
How to replace all comments inside code without remove crln  = \r\n or cr \r each line?

<?php
$txt_target=<<<t1
this;//    dsdsds
    nope
    
/*
    ok
    */
is;huge
/*text bla*/
    /*bla*/
 
t1;

/*
=======================================================================
expected result:
=======================================================================
this;
    nope

is;huge
=======================================================================
visualizing in a hex viewer .. to_check_with_a_hex_viewer.txt ...
 t  h  i  s  ; LF TAB n  o  p  e CR LF CR LF  i  s  ;  h  u  g  e CR LF
74 68 69 73 3b 0a 09 6e 6f 70 65 0d 0a 0d 0a 69 73 3b 68 75 67 65 0d 0a
I used F3 (viewer + options 3: hex) in mythical TOTAL COMMANDER!
=======================================================================
*/

echo '<hr><pre>';
echo  $txt_target;
echo '</pre>';

//  a single line '//' comments
$txt_target = preg_replace('![ \t]*//.*[ \t]*!', '', $txt_target);

//  /* comment */
$txt_target = preg_replace('/\/\*([^\/]*)\*\/(\s+)/smi', '', $txt_target);
echo '<hr><pre>';
echo  $txt_target;
echo '</pre><hr>';

file_put_contents('to_check_with_a_hex_viewer.txt',$txt_target);

?>

<< Back to user notes page

To Top