It can't be done with PHP alone, you need a bit of JavaScript for the client-side operations (opening a new window).
<?php
function getPHPSelf() {
if (isset($_SERVER['PATH_INFO']) && strlen($_SERVER['PATH_INFO'])> 0) {
return substr($_SERVER['PHP_SELF'],0,(strlen($_SERVER['PHP_SELF']) - @strlen($_SERVER['PATH_INFO'])));
}
else {
return $_SERVER['PHP_SELF'];
}
}
if (isset($_POST['submit'])) {
$search = $_POST['search'];
$fblink = "<script>window.open('https://www.google.com/webhp?q=".$search."+site:facebook.com', 'width=700,height=700,left=100,top=100')</script>";
$twlink = "<script>window.open('https://www.google.com/webhp?q=".$search."+site:twitter.com', 'width=700,height=700,left=100,top=100')</script>";
$iglink = "<script>window.open('https://www.google.com/webhp?q=".$search."+site:instagram.com', 'width=700,height=700,left=100,top=100')</script>";
$sclink = "<script>window.open('https://www.google.com/webhp?q=".$search."+site:soundcloud.com', 'width=700,height=700,left=100,top=100')</script>";
echo $fblink;
echo $twlink;
echo $iglink;
echo $sclink;
}
else {
echo "<form enctype=\"multipart/form-data\" action=\"".getPHPSelf()."\" method=\"POST\">";
echo "Search: <input type=\"text\" size=\"50\" name=\"search\">";
echo "<input type=\"submit\" value=\"Search\" name=\"submit\">";
echo "</table>";
echo "</form>";
}
?>