Hi I need help with the php code <?php $current_url = "http://" .$_SERVER['HTTP_HOST'] .$_SERVER['REQUEST_URI']; print $current_url ?> this is gonna return a url ( a string ) with exactly this pattern ( so dont have to worry much about the logics fo the url returned) http://yoursite.com/node/123/idontwant_thisstuff or could be http://yoursite.com/?q=node/123/idontwant_thisstuff Basically i want to run a loop to get rid of "/idontwant_thisstuff" i.e anything after node/87/... should get deleted. i.e i just want url two main things first the word "node"( ofcourse the base url also http://yoursite.com/ ) and the numeric value proceeding it. eg http://yoursite.com/node/1/events ---> http://yoursite.com/node/1 http://yoursite.com/node/123423423/groups -----> http://yoursite.com/node/123423423 please if someone could do this Having working since morning on drupal, and this is the last step(except some css work) to achieve my goals. please help me out Thanks Himtuna
I am not sure you are pulling the right information to do what you want and I do not have enough experience to write the code from scratch without testing it. I think a better approach might be contained in this script fragment which I think does what does what you want. Remove the remarks (//) to debug it for your use. Post back and let us know if that worked.
<?php $url = "$_SERVER['HTTP_HOST'] .$_SERVER['REQUEST_URI'];" $str = explode("/",$url); echo "$str[1]/$str[2]/$str[3]"; ?> PHP:
I used this (drupal specific) <?php if ( arg(0) == 'node' && is_numeric(arg(1)) ) { $my_id = arg(1); echo $my_id ; } ?> Code (markup): All you would have to do is echo the domain and ?node= . Course will require php formatting in drupal. And I'm not sure if it works with extra crud on the query string.
Thanks a lot to every one. @shallowink Your code does what I wanted. How to get the base url of the the drupal