I have a URL like this : www.test.fr/dir/file.html#hello
I would delete everything after the character #
. I have try this /#[a-z0-9]+/
You code is almost correct, this works just fine:
$new = preg_replace('/#[a-z0-9]+/', '', 'www.test.fr/dir/file.html#hello');
print ($new);
prints:
www.test.fr/dir/file.html
You can test it here
You can explode by '#' and get the first position. Something like this:
$url = "www.test.fr/dir/file.html#hello";
$result = explode("#",$url)[0];