The Little Guy Posted October 20, 2008 Share Posted October 20, 2008 If I have a URL like this: http://dudeel.com/#calculate how can I get the text after the pound sign? Link to comment https://forums.phpfreaks.com/topic/129184-solved-get-text-after/ Share on other sites More sharing options...
CroNiX Posted October 20, 2008 Share Posted October 20, 2008 Little helper function I have used: <?php //return url hash or empty string function getHash($url){ $pos=strpos($url, "#"); return ($pos !== false) ? substr($url, $pos+1) : ""; } Link to comment https://forums.phpfreaks.com/topic/129184-solved-get-text-after/#findComment-669772 Share on other sites More sharing options...
Psycho Posted October 20, 2008 Share Posted October 20, 2008 function getURLParam(URLstr) { return URLstr.replace(/.*#/, ''); } @CroNiX: This is the JavaScript forum. You posted PHP code. Link to comment https://forums.phpfreaks.com/topic/129184-solved-get-text-after/#findComment-669773 Share on other sites More sharing options...
CroNiX Posted October 20, 2008 Share Posted October 20, 2008 Ah, even easier... var hash = document.location.hash; Link to comment https://forums.phpfreaks.com/topic/129184-solved-get-text-after/#findComment-669784 Share on other sites More sharing options...
The Little Guy Posted October 20, 2008 Author Share Posted October 20, 2008 I use this: var curl = document.location; alert(curl.replace(/.*#/, '')); and it redirects me to this page: http://dudeel.com/.*#/ Link to comment https://forums.phpfreaks.com/topic/129184-solved-get-text-after/#findComment-669788 Share on other sites More sharing options...
Psycho Posted October 20, 2008 Share Posted October 20, 2008 Nice find on the .hash property - wasn't aware of that one. however, that assumes you are dealing with an object with that parameter value. If the URL is just a text object, it will not have a hash property. Link to comment https://forums.phpfreaks.com/topic/129184-solved-get-text-after/#findComment-670119 Share on other sites More sharing options...
CroNiX Posted October 20, 2008 Share Posted October 20, 2008 function getHashFromURL(url){ var pos=str.indexOf('#'); return (pos!=-1) ? url.substr(pos+1) : ''; } Link to comment https://forums.phpfreaks.com/topic/129184-solved-get-text-after/#findComment-670144 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.