-3

I get an error,

Warning: preg_replace(): No ending delimiter '#' found

on this line,

$sql = preg_replace("\n#[^\n]*\n", "\n", $sql);

on this function,

function split_sql($sql) {
    $sql = trim($sql);
    $sql = preg_replace("\n#[^\n]*\n", "\n", $sql);

    $buffer = array();
    $ret = array();
    $in_string = false;

    for($i=0; $i<strlen($sql)-1; $i++) {
        if($sql[$i] == ";" && !$in_string) {
            $ret[] = substr($sql, 0, $i);
            $sql = substr($sql, $i + 1);
            $i = 0;
        }

        if($in_string && ($sql[$i] == $in_string) && $buffer[1] != "\\") {
            $in_string = false;
        }
        elseif(!$in_string && ($sql[$i] == '"' || $sql[$i] == "'") && (!isset($buffer[0]) || $buffer[0] != "\\")) {
            $in_string = $sql[$i];
        }
        if(isset($buffer[1])) {
            $buffer[0] = $buffer[1];
        }
        $buffer[1] = $sql[$i];
    }

    if(!empty($sql)) {
        $ret[] = $sql;
    }
    return($ret);
}
Explosion Pills
  • 188,624
  • 52
  • 326
  • 405
Vimux
  • 17
  • 3
  • @rae1n It's the question title. – Niet the Dark Absol Jan 21 '13 at 16:21
  • @rae1n Are we `going` to `argue` semantics? It's the cause of the OP's problems and the reason why it's not working as expected. What error are you expecting? There are no more valid errors to return from the OPs code that would help in debugging this at all. – nickb Jan 21 '13 at 16:28
  • I'm arguing OP should put a bit more effort so someone else can help the issue. – rae1 Jan 21 '13 at 16:30

1 Answers1

2

The delimiter must be a non-alphanumeric, non-whitespace character. It is seeing the # as the delimiter for this reason, and therefore looks for another one and can't find it.

Try preg_replace("/\n#[^\n]*\n/","\n",$sql);

Niet the Dark Absol
  • 320,036
  • 81
  • 464
  • 592