function merge($segment) { if ($this->contains($segment)) { for ($i = $this->getEnd(); $i <= $segment->getEnd(); $i++) { $this->text[$i] = $segment->text[$i]; } $new_segment = new Segment($this->text, $this->getStart(), $segment->getEnd()); $new_segment->setNeedles(array_merge($this->needle_positions, $segment->needle_positions)); return $new_segment; } return False; }