replace all special character and multiple spaces with hyphon(-)

echo $string=’Google@stop#page!r$a.nk? Google: We Won\’t Be U$p%d^a&t*i(n)g T{o}o|l\b”a:r P;a`g~e                        Rank’;
echo “<br>”;
$ro = preg_replace(‘/\s+/’, ‘ ‘,$string);
echo strtolower(str_replace(array(‘  ‘, ‘ ‘), ‘-‘, preg_replace(‘/[^a-zA-Z0-9 s]/’, ‘ ‘, trim($ro))));

result :

google-stop-page-r-a-nk-google-we-won-t-be-u-p-d-a-t-i-n-g-t-o-o-l-b-a-r-p-a-g-e-rank

Get previous url in php and javascript

//code for index.php

<a href=”previous-url.php”>click for php</a>
<a href=”previous-url-javascript.php”>click for javascript</a>

//code for previous-url.php

echo $a=$_SERVER[‘HTTP_REFERER’];

//code for previous-url-javascript.php

<button onclick=”goBack()”>Go 2 pages back</button>

<p>Notice that clicking on the “Go 2 pages back” button here will not result in any action, because there is no previous URL in the history list.</p>

function goBack() {
window.history.go(-2);
}