Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/150468-need-string-formatted/
Share on other sites

Thanks this is real awesome code

but  a little problem( but once i move my site online this will be rectified as I dont have clean urls) is that ?= appears in the query just before the 'node' so its not giving the desired results. Drupal is not going to generate anything other than 'node' as a first argument.

 

A drupal guy gave me this code( it uses drupal variables)

 

<?php

if ( arg(0) == 'node' && is_numeric(arg(1)) ) {

  $my_id = arg(1);

  echo $my_id ;

}

?>

 

But your solution has opened my mind, so hardcore programmer.

Thanks buddy

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.