Laravel 根据来自 Db 的内容中的表达式查找和替换内容

Laravel find and replace content on the basis of a expression in content coming from Db

我有一个博客内容,管理员可以在其中添加这样的模式 => %make123%。 当要显示该内容时,我必须将 %make123% 替换为车辆 ID 123,但现在如何从我的内容中获取 123。然后进行另一个查询以搜索具有该 ID 的车辆。

这是我的博客详细信息控制器功能。

function blogDetail($blog_id, $title_link){

$dataSetArray = array();
$dataSetArray['route'] = '/blog/:blog_title';

$rs = "SELECT id, post_title, post_meta_title, post_author, post_meta_description, 
post_meta_keywords, 
post_content, post_image, DATE_FORMAT(created_at, '%d-%b-%Y') as created_at FROM blog_post
where id = '$blog_id' AND CONCAT( CONCAT( CONCAT( SUBSTRING(MY_TITLE(post_title), 1, 50),'-'), 
id),'.html') = '$title_link' ";
$results = DB::select($rs);





$results = json_decode(json_encode($results), true);
foreach ($results as $key => $value){
  $content =  $value['post_content'];
}

$pattern = '/%make(.+?)%/';

preg_match_all($pattern,$content,
$out, PREG_PATTERN_ORDER);


}

后端在laravel前端在react js

使用正则表达式从给定的字符串中获取您的内容 ID。

$regex = '/(%)([a-zA-Z]*)([0-9]*)(%)/m';
    
preg_match_all($regex, $content, $matches, PREG_SET_ORDER, 0);
    
// Print the entire match result
echo "<pre>";
print_r($matches[0][3]);
echo "</pre>";