Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I have seen a very similar question here at SO or drupal SO page but couldn't find it so I'm writing "my way" answer again here. </p> <pre><code>&lt;?php function _pagepeeker_format_url($url, $domain_only = FALSE) { if (filter_var($url, FILTER_VALIDATE_URL) === FALSE) { return FALSE; } //$url = 'http://www.google.com/url?sa=X&amp;q=http://www.beautyjunkiesunite.com/WP/2012/05/30/whats-new-anastasia-beverly-hills-lash-genius/&amp;ct=ga&amp;cad=CAcQARgAIAEoATAAOABA3t-Y_gRIAlgBYgVlbi1VUw&amp;cd=F7w9TwL-6ao&amp;usg=AFQjCNG2rbJCENvRR2_k6pL9RntjP66Rvg'; // Now we use parse_url to split the url to an array with url parts. $parsed_url = parse_url($url); // $parsed_url['query'] is 'sa=X&amp;q=http://www.beautyjunkiesunite.com/WP/2012/05/30/whats-new-anastasia-beverly-hills-lash-genius/&amp;ct=ga&amp;cad=CAcQARgAIAEoATAAOABA3t-Y_gRIAlgBYgVlbi1VUw&amp;cd=F7w9TwL-6ao&amp;usg=AFQjCNG2rbJCENvRR2_k6pL9RntjP66Rvg' // ";" can also be used to separate params. But &amp; is the usual one so using it. $queryParts = explode('&amp;', $parsed_url['query']); $params = array(); foreach ($queryParts as $param) { $item = explode('=', $param); // sa = X, etc. $params[$item[0]] = $item[1]; } //$params is now an array with query parts. // $params['sa'] = 'X' , q = 'http://www.beautyjunkiesunite.com/WP/2012/05/30/whats-new-anastasia-beverly-hills-lash-genius', etc. if ($domain_only){ $new_url_parsts = parse_url($params['q']); return $new_url_parts['host']; } else{ return $params['q']; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload