Reputation: 1234
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]+/
www.test.fr/dir/file.html#hello
#
/#[a-z0-9]+/
Upvotes: 2
Views: 84
Reputation: 6928
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
Reputation: 1575
You can explode by '#' and get the first position. Something like this:
$url = "www.test.fr/dir/file.html#hello"; $result = explode("#",$url)[0];
Upvotes: 1