CMS custom: Automatically add text after two paragraphs using php

one text

I am creating a custom cms. Everything works fine, but I am unable to add a banner ads in a certain position of the text. The content of the article in html is found inside the $content variable. I can count the paragraphs present, using the function:

substr_count($content, 'is');

now I would like to add a banner or other text after two paragraphs, but I can't understand how I can do it. Could someone help me.

Source