Use a positive lookahead to check for the links which are going to be matched wouldn't be followed by a closing php or code tag.
$content = <<
Output:
Link_1: [code]This is a textual line.
LINK HIDDEN
This is a textual line.[/code]
Link_2: [php]This is a textual line.
LINK HIDDEN
This is a textual line.[/php]