match a // in a line of array and replace // with blank space if its not inside " ".
For example I have this line:
//this is a test
"this is a // test"
the output should be:
"this is a // test"
it will ignore // inside ""
for now I’ve come up with this regex:
$string[$i] = preg_replace('#(?<!")//.*(?!")#',' ',$string[$i]);
but this does’t work if the // is in the middle or last part of a line.
Since you don’t have to worry about quotes that span multiple lines, this makes your job significantly easier.
One approach would be to go through the input line-by-line and
explode()each line using"as the delimiter:Using the following test string:
We get the following output: