Is there any clean grep one-liner to grep only the PHP source (the code between <?
and ?>
) from a PHP file? Thus far I've tried:
grep -oiE "<\?php[[:print:]]*\?>" name_of_php_file
But it seems to return muddled entries like:
<?php print $row[0];?>"><img src="gallerybig/<?php echo $row[1];?>
Expecting a one-liner which would return only PHP source, without any muddled entries. sed and awk are OK.
EDIT: The expected output is PHP source code, even if it spans multiple lines. The sample output is bad, as it contains HTML in between: "><img src="gallerybig/
EDIT 2: The answer given by @SigmaPiEpsilon works, but grep doesn't print code that spans multiple lines. For example, this snippet of code doesn't show up in the output:
<?php
$str="select c_id,c_description,cate_name,date from book_table ;";
$res=mysql_query($str); ?>