UK-1991 0 Posting Whiz

I have created a function for displaying the shortcode within my content same as like don in wordpress not totally like it but some the thing is that when the regex becomes true will display shortcode for the given name but what happening now is it's displaying all within the array as the the shortcode of that name does not exist in the content how can I make this proper functional.

This is my content This is a test page use to check the property [shortcode name='slider']

the shortcode is for slider so it will show the slider but in my case it's displaying all code

<?php 
                    $page_content = $pages->row()->content;
                    $contentRegex = strip_tags($page_content);
                    $content      = str_replace("&#39;", "'", $contentRegex);
                    $regex        = '~\[.*?name=([\'"])([^\'"]+)\1\]~';

                    $content = preg_replace_callback($regex,
                        function ($match) {
                                $replacements = array(
                                    'slider'      => slider(),
                                    'corusel'     => corusel(),
                                    'contact'     => contact(),
                                    'social'      => social(),
                                    'testimonial' => testimonial()
                                );
                                $key = $match[2];
                                $replacements[$key];
                                return $replacements[$key];
                            },
                            $content
                        );      
                    echo $content;

                ?>

If I remove the echo from content the shortcode is still displaying and below is the sample function for shortcode

       function slider() {
                return $convert = require('slider.php');
       }

Can anyone help me out and please if not understood or have doubt please ask me for detail as I am not a good explainer.

Thank You