I wish to use php to look the present url for com_agora and when it finds it to show something and when it does not to show another thing

the issue is there might be plenty of figures after com_agora within the url

a good example could be this com_agora&task=cat_view&gid=41&Itemid=

just how would I tell it think it is whilst not caring what figures come following a?

$uri = $_SERVER['REQUEST_URI']; // or taken from another source //
if( strpos($uri, 'com_agora') !== false ){
   // Your action goes here! //

If you want more complicated parameters procedures please use parse_str.

I'm presuming you're speaking concerning the query string here (the part following the ?)

For any bullet-proof approach, use [cde] to consider apart the query string and also to decide if there's a parameter named parse_str(). It has the benefit that it'll ignore the appearance of the search phrase elsewhere within the string (e.g. in another parameter value).

$query_string = $_SERVER["QUERY_STRING"]; // e.g. com_agora&task=cat_view
$query_string_parsed = array();       

parse_str($query_string, $query_string_parsed); 

// Search for "com_agora"
$found = array_key_exists("com_agora", $query_string_parsed); 

Joomla includes a class that enables you to utilize URL if(strpos($url, 'com_agora') !== FALSE) { /* do something */ } , you are able to learn more about [cde] class on Joomla's documentation site.

Here's completely functional code, that is going to do that which you what it really to complete


When you are in Joomla function this:


The $option variable will hold the need for whatever is incorporated in the URL and you will go:


// Sample URL
$url = "http://www.mysite.com/index.php?option=com_agora&task=cat_view&gid=41&Itemid=5";

// Using JFactory::getURI() without parameter will give you URI of current webpage
$uri = JFactory::getURI($url);

// Here is the structure of the object
//  public '_uri' => string 'http://www.mysite.com/index.php?option=com_agora&task=cat_view&gid=41&Itemid=5' (length=78)
//  public '_scheme' => string 'http' (length=4)
//  public '_host' => string 'www.mysite.com' (length=14)
//  public '_port' => null
//  public '_user' => null
//  public '_pass' => null
//  public '_path' => string '/index.php' (length=10)
//  public '_query' => string 'option=com_agora&task=cat_view&gid=41&Itemid=5' (length=46)
//  public '_fragment' => null
//  public '_vars' => 
//    array
//      'option' => string 'com_agora' (length=9)
//      'task' => string 'cat_view' (length=8)
//      'gid' => string '41' (length=2)
//      'Itemid' => string '5' (length=1)

// Get and output option parameter from the URI
echo 'Option = ' . $uri->getVar('option');
//  output = com_agora