I tried to make a custom php shortcode coverter for my own cms but the shortcodes are not converting in a proper way in the output its not displaying anything though as in replacement of corusel it should display Rollercoaster but right now I am getting output as This is a test page use to check the property [shortcode name='corusel'] but it should display as
This is a test page use to check the property Rollercoaster can anyone help me out with this concern please
<?php
// both content are same
//<p> This is a test page use to check the property [shortcode name='corusel']</p>
// In database table it stored in this format
$page_content = $pages->row()->content; //When I run this it did not replaced
$content = "This is a test page use to check the property [shortcode name='corusel']"; //When I run this it replaced
$regex = '~\[.*?name=([\'"])([^\'"]+)\1\]~';
$content = preg_replace_callback($regex,
function ($match) {
$replacements = array('corusel' => 'Rollercoaster');//this is the value which is being replaced with [shortcode name='corusel']
$match[2];
$key = $match[2];
return $replacements[$key];
},
$content
);
echo $content
?>