1

I was trying to make this function more comprehensive to parse more of a url

Currently the function I have is this

function _pagepeeker_format_url($url = FALSE) {
if (filter_var($url, FILTER_VALIDATE_URL) === FALSE) {
return FALSE;
}

// try to parse the url
$parsed_url = parse_url($url);
if (!empty($parsed_url)) {
$host = (!empty($parsed_url['host'])) ? $parsed_url['host'] : '';
$port = (!empty($parsed_url['port'])) ? ':' . $parsed_url['port'] : '';
$path = (!empty($parsed_url['path'])) ? $parsed_url['path'] : '';
$query = (!empty($parsed_url['query'])) ? '?' . $parsed_url['query'] : '';
$fragment = (!empty($parsed_url['fragment'])) ? '#' . $parsed_url['fragment'] : '';
return $host . $port . $path . $query . $fragment;

}

return FALSE;
}  

This function turns urls that look like this

http://www.google.com/url?sa=X&q=http://www.beautyjunkiesunite.com/WP/2012/05/30/whats-new-anastasia-beverly-hills-lash-genius/&ct=ga&cad=CAcQARgAIAEoATAAOABA3t-Y_gRIAlgBYgVlbi1VUw&cd=F7w9TwL-6ao&usg=AFQjCNG2rbJCENvRR2_k6pL9RntjP66Rvg

into this

http://www.google.com/url

Is there anyway to make this array return the entire url instead of just part of it ?

I have looked at the parse_url php page and it helps and searched the stackoverflow and found a couple of things I am just having a bit of trouble grasping the next step here.

Let me know if I can clarify in any way

thanks!!

naeluh
  • 951
  • 11
  • 17

2 Answers2

1
return $url;

Or am I missing something?

Jeroen
  • 13,056
  • 4
  • 42
  • 63
0

this is what i use (getting rid of parse_url and such):

function get_full_url() {
    // check SSL
    $ssl = "";
    if ((isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"]=="on") || (isset($_SERVER["SERVER_PORT"]) && $_SERVER["SERVER_PORT"]=="443")) 
      { $ssl = "s"; }
    $serverport = ($_SERVER["SERVER_PORT"]!="80"?":".$_SERVER["SERVER_PORT"]:"");
    return "http".$ssl."://".$_SERVER["SERVER_NAME"].$serverport.$_SERVER["REQUEST_URI"];
}

just call get_full_url(); from anywhere in your script.

  • Okay I will try this. Does this use the same logic as parse_url without using parse_url because I think might need to use it as this is a function for a drupal module. Would this be all I need to grab the full url? Also what would I return ? thanks very much for your help!! – naeluh May 31 '12 at 18:11
  • You return the $fullurl, which hopefully contains the full url. The parse_url just explode a GIVEN url into parts (protocol,query etc.) but this one tries to build it from $_SERVER info. –  May 31 '12 at 18:25
  • cool so I would just add return $fullurl; but my function doesn't contain $fullurl does that matter ? – naeluh May 31 '12 at 18:27
  • Hmm ya know what it returned a really weird url and looks as though it was trying to return the page url. It returned http://:10717/content/anastasia-beverly-hills-line-erasing-serum-05-fl-oz-eyes-anastasia looks as though it using the url of the page and some server info. I think I miss spoke - there is a url that is coming from an rss feed that needs to stay intact after it gets processed by the parse_url not change completely. Let me know if I can clarify. thanks for your help – naeluh May 31 '12 at 18:37
  • Do you see what I mean? I have a url coming from rss? – naeluh May 31 '12 at 18:41
  • im confused; what is your rss url and what this has to do with that google url in your first post? also, i see that you emulate the parse_url() ?!?! –  May 31 '12 at 18:45
  • Please look at this post and it will explain more what I am trying to do. http://stackoverflow.com/questions/10837707/url-cutoff-by-link-module-or-pagepeeker-formatter-issue-in-drupal-7 – naeluh May 31 '12 at 18:47
  • I am trying to keep the full url to complete a request to a screenshot server via drupal. The pagepeeker module's parse_url function is trimming the url which returning the wrong page – naeluh May 31 '12 at 18:52