Here is the answer if your blog is not in the root directory.
<?
$URI_prefix = "/blog/";
$search_preterm = str_replace($URI_prefix,"",$_SERVER['REQUEST_URI']);
$search_term = substr($_SERVER['REQUEST_URI'],1);
$search_term = stripslashes($search_preterm);
$search_term = urldecode(stripslashes($search_term));
$search_url = 'https://davidblog.ws/blog/index.php?s=';
$full_search_url = $search_url . $search_term;
$full_search_url = preg_replace('/ /', '%20', $full_search_url);
$full_page = implode("", file($full_search_url));
print_r($full_page); die();
?>
Change /blog/ to whatever subdirectory your blog is in.
Also.. You may want your .htacess in your blog dir to call a slightly different 404.php file (I call 404blog.php) that way the search text is formatted correctly regardless of whether the original 404 occurs in your root or blog directory.
Carl..
Your problem is because the code on original page is styled (in some way) on the authors page. Therefore you need to strip the styling or just copy what is below.
<?
$search_term = substr($_SERVER['REQUEST_URI'],1);
$search_term = urldecode(stripslashes($search_term));
$search_url = 'https://davidblog.ws/blog/index.php?s=';
$full_search_url = $search_url . $search_term;
$full_search_url = preg_replace('/ /', '%20', $full_search_url);
$full_page = implode("", file($full_search_url));
print_r($full_page); die();
?>